Intersection of Two Linked Lists--LeetCode
来源:互联网 发布:趋势波段买卖指标源码 编辑:程序博客网 时间:2024/06/17 19:47
Write a program to find the node at which the intersection of two singly linked lists begins.
For example, the following two linked lists:
A: a1 → a2 ↘ c1 → c2 → c3 ↗ B: b1 → b2 → b3
begin to intersect at node c1.
找第一个相遇的节点,看哪个长,然后往前走几个节点,继续查看您能够相等
List* getIntersectionNode(List* first,List* second){ if(first == NULL) return second; if(second == NULL) return first; List* headA= first; List* headB = second; int lenA=0,lenB=0; while(headA != NULL) { lenA++; headA = headA->next; } while(headB != NULL) { lenB++; headB = headB->next; } headA = first; headB = second; if(lenB > lenA) { while(lenA !=lenB) { headA = headA->next; lenA++; } } else if(lenA > lenB) { while(lenA != lenB) { headB = headB->next; lenB++; } } while(headA != NULL && headB !=NULL) { if(headA == headB) return headA; else { headA = headA->next; headB = headB->next; } } return NULL; }
0 0
- [leetcode] [leetcode]Intersection of Two Linked Lists
- 【LeetCode】Intersection of Two Linked Lists
- LeetCode: Intersection of Two Linked Lists
- [Leetcode] Intersection of Two Linked Lists
- [Leetcode]Intersection of Two Linked Lists
- LeetCode:Intersection of Two Linked Lists
- leetcode: Intersection of Two Linked Lists
- Leetcode: Intersection of Two Linked Lists
- Intersection of Two Linked Lists--leetcode
- [leetcode]Intersection of Two Linked Lists
- leetcode:Intersection of Two Linked Lists
- leetcode之Intersection of Two Linked Lists
- 【Leetcode】:Intersection of Two Linked Lists
- leetcode Intersection of Two Linked Lists
- [LeetCode]Intersection of Two Linked Lists
- leetcode: Intersection of Two Linked Lists
- 【LeetCode】Intersection of Two Linked Lists
- LeetCode Intersection of Two Linked Lists
- 7-1通信系统中为什么要进行编码和解码?常见的编码方法有哪些?
- 二叉搜索树
- hdoj Color the ball
- U3D中ShaderForge插件使用系列教程之一
- 增量型编码器驱动
- Intersection of Two Linked Lists--LeetCode
- Python 的 “ SyntaxError: invalid syntax ”
- 通信系统中为什么要进行调制和解调?调制的分类方法有哪些?
- Hadoop家族产品学习路线
- RFID第三次作业:7.1和7.2
- 红黑树(二叉搜索树的一种)
- JavaScript对象的创建方法及其优缺点
- [Windows通用应用开发]Toast通知(一)——Toast实现
- 3.linux帐户管理