我刷LeetCode的顺序是先刷简单题,再刷中等题,并且按类型刷。有同学说按类型刷,相当于提示答案了,这就要看是以学习的方式刷题还是以测试的方式刷题。我把刷题的过程记录下来,以便二刷三… 半情调 有了这套模板,女朋友再也不用担心我刷不动 LeetCode 了 作者| 李威 来源 | https://www.liwei.party/整理 | 公众号:五分钟学算法
publicboolisLoopList(ListNode<T> head){ListNode<T> slowPointer, fastPointer;//使用快慢指针,慢指针每次向前一步,快指针每次两步slowPointer = fastPointer = head;while(fastPointer != null && fastPointer.next != null){slowPointer = slowPointer.next;fastPointer = fastPointer.next.next;//两指针相...
前言 最近有朋友问我怎么没有更新文章了,因为最近有空的时候都在刷 LeetCode,零零星星刷了快 2 个月了,也累积了不少题目了,所以最近打算把做的几百道题归类,总结一下。所有题目的代码在github.com/halfrost/Le…,每道题都有测试用例和测试代码。 Linked List 的 Tips: 巧妙的构造虚拟头结点。可以使遍历处理...
206. Reverse Linked List 逆序整个链表。逆序操作可以看作:依次遍历链表,将当前结点插入到链表头。 publicListNodereverseList(ListNode head){ListNodenewHead=null;for(ListNodecurr=head; curr !=null; ) {ListNodetemp=curr.next; curr.next = newHead;// insert to the head of listnewHead = curr; curr ...
Input:head = [3,2,0,-4], pos = 1Output:tail connects to node index 1Explanation:There is a cycle in the linked list, where tail connects to the second node. Example 2: Input:head = [1,2], pos = 0Output:tail connects to node index 0Explanation:There is a cycle in the linked...
面试leetcode 算法专题系列(二)—— 链表 除夕发表于除夕酱的刷... 刷了LeetCode的链表专题,我发现了一个秘密! Drink凉白开 Leetcode:刷完31道链表题的一点总结 前言 今天终于刷完了 Leetcode 上的 链表专题,虽然只有 31 道题(总共是 35 道,但有 4 道题加了锁)而已,但也陆陆续续做了两三个星期,严重...
Can you solve this real interview question? Linked List in Binary Tree - Given a binary tree root and a linked list with head as the first node. Return True if all the elements in the linked list starting from the head correspond to some downward path
141 Linked..判断链表 LinkList 是否带循环。Given a linked list, determine if it has a cycle in it.To represent a cycle in t
Explanation: In the figure above, there is a sorted circular list of three elements. You are given a reference to the node with value 3, and we need to insert 2 into the list. The new node should be inserted between node 1 and node 3. After the insertion, ...
如果listA和listB有交点,intersectVal == listA[skipA + 1] == listB[skipB + 1] 进阶:你能否设计一个时间复杂度O(n)、仅用O(1)内存的解决方案? 题目难度:简单 通过次数:304.5K 提交次数:452.2K 贡献者:LeetCode 您必须登录后才能提交解答!