160. Intersection of Two Linked Lists
来源:互联网 发布:excel相同数据自动合并 编辑:程序博客网 时间:2024/05/29 17:35
class Solution {public: ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { if(0 == headA || headB == 0) return NULL; int len1 = 0, len2 = 0; ListNode *p; for(p = headA; p != NULL; p = p->next, ++len1); for(p = headB; p != NULL; p = p->next, ++len2); ListNode *p1 = headA, *p2 = headB; if(len1 > len2){ int gap = len1 - len2; while(gap--){ p1 = p1->next; } }else if(len2 > len1){ int gap = len2 - len1; while(gap--){ p2 = p2->next; } } while(p1 && p2){ if(p1 == p2) return p1; p1 = p1->next; p2 = p2->next; } return NULL; }};
阅读全文
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
- 160. Intersection of Two Linked Lists
- 160. Intersection of Two Linked Lists
- [LeetCode]160. Intersection of Two Linked Lists
- 160. Intersection of Two Linked Lists
- 160. Intersection of Two Linked Lists
- LeetCode--160. Intersection of Two Linked Lists
- 160. Intersection of Two Linked Lists
- LeetCode 160. Intersection of Two Linked Lists
- 160. Intersection of Two Linked Lists
- 160. Intersection of Two Linked Lists
- 160. Intersection of Two Linked Lists
- 【LeetCode】160. Intersection of Two Linked Lists
- 160. Intersection of Two Linked Lists
- 160. Intersection of Two Linked Lists
- css 之 border-radius属性
- ELK服务搭建(一)之初识
- DNS及解析过程
- 自定义注解实战
- 像经济学家一样思考
- 160. Intersection of Two Linked Lists
- 【MQ】ActiveMQ总体概览
- 每日一则JavaWeb---Spring之ContextLoaderListener
- ELK服务搭建(二)之Kibana使用说明
- 【Linux】5Linux安装Mysql\禅道
- ajax乱码问题解决方式
- aes 源码(c)
- 【中兴笔试题】求两个圆的交叉区域的面积
- netty3中Handler之间传递数据