[LeetCode]160. Intersection of Two Linked Lists
来源:互联网 发布:pdf转jpg软件 编辑:程序博客网 时间:2024/05/21 06:27
https://leetcode.com/problems/intersection-of-two-linked-lists/
找到第一个相同的节点
让长的链表的指针先移动差值距离,然后同时移动,判断是否当前节点相同
public class Solution { public ListNode getIntersectionNode(ListNode headA, ListNode headB) { int sizeA = 0; int sizeB = 0; ListNode curA = headA; ListNode curB = headB; while (curA != null) { sizeA++; curA = curA.next; } while (curB != null) { sizeB++; curB = curB.next; } while (sizeA > sizeB) { headA = headA.next; sizeA--; } while (sizeA < sizeB) { headB = headB.next; sizeB--; } while (headA != headB) { headA = headA.next; headB = headB.next; } return headA; }}
0 0
- [LeetCode]160.Intersection of Two Linked Lists
- LeetCode 160. Intersection of Two Linked Lists
- 【LeetCode】160.Intersection of Two Linked Lists
- [leetcode] 160.Intersection of Two Linked Lists
- [LeetCode]160. Intersection of Two Linked Lists
- LeetCode--160. Intersection of Two Linked Lists
- LeetCode 160. Intersection of Two Linked Lists
- 【LeetCode】160. Intersection of Two Linked Lists
- Leetcode 160. Intersection of Two Linked Lists
- LeetCode *** 160. Intersection of Two Linked Lists
- LeetCode 160. Intersection of Two Linked Lists
- leetcode-160. Intersection of Two Linked Lists
- LeetCode-160.Intersection of Two Linked Lists
- LeetCode 160. Intersection of Two Linked Lists
- Leetcode 160. Intersection of Two Linked Lists
- LeetCode 160. Intersection of Two Linked Lists
- leetcode 160. Intersection of Two Linked Lists
- 160.[Leetcode]Intersection of Two Linked Lists
- Centos 6.5 安装java及设置默认jdk版本
- 素数
- Redis源码剖析--数据库db
- linux 下解决umount 时出现的 "Device is busy"问题
- 数据库范式-例子很好
- [LeetCode]160. Intersection of Two Linked Lists
- 【Qt】QString之simplified()小记
- iOS 下Sqlite的简单使用
- 在Linux下安装rpm包时,提示error: Failed dependencies
- Android中RecyclerView用法
- IIS 中部署 Asp.Net
- 信号量与互斥锁
- 数据库总结
- VirtualBox虚拟机迁移方法