![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
tiger-guo
这个作者很懒,什么都没留下…
展开
-
141. Linked List Cycle 和 83. Remove Duplicates from Sorted List java代码实现
141题其实就是判断链表是否有环 判断时候有环(链表头指针为head) 对于这个问题我们可以采用“快慢指针”的方法。就是有两个指针fast和slow,开始的时候两个指针都指向链表头head,然后在每一步 操作中slow向前走一步即:slow = slow->next,而fast每一步向前两步即:fast = fast->next->next。 由于fast要比slow移动的快,如...原创 2019-05-30 22:55:30 · 59 阅读 · 0 评论 -
160. Intersection of Two Linked Lists java实现
两个链接列表的交集 编写程序以找到两个单链表开头的节点。 例如,以下两个链表: 开始在节点c1处相交。 解法一: public class Solution { public ListNode getIntersectionNode(ListNode headA, ListNode headB) { if(headA == null || headB == null)...原创 2019-05-29 00:48:10 · 155 阅读 · 0 评论 -
203. Remove Linked List Elements 206. Reverse Linked List java实现
题目:203.Remove all elements from a linked list of integers that have value val. class Solution { public ListNode removeElements(ListNode head, int val) { if(head == null) return head; ...原创 2019-05-31 22:47:47 · 88 阅读 · 0 评论 -
234. Palindrome Linked List java实现
234.Given a singly linked list, determine if it is a palindrome. 这个代码时间复杂度和空间复杂度虽然不咋地,但是,这个想法很优秀,用递归实现了链表的倒序,自己画一下运行步骤,一下子就看出来了。 class Solution { ListNode first = null; public boolean isPali...原创 2019-06-02 00:10:30 · 156 阅读 · 0 评论 -
21. Merge Two Sorted Lists java代码实现
21、合并两排序链表 合并两个已排序的链接列表并将其作为新列表返回。新列表应该通过拼接前两个列表的节点来完成。Example: Input: 1->2->4, 1->3->4Output: 1->1->2->3->4->4 #### 解法一:先将两链表结点值进行比较添加到新链表中,之后将剩余链表结点接在新链表后面。 class Solut...原创 2019-05-29 22:40:25 · 463 阅读 · 0 评论