LeetCode || Intersection of Two Linked Lists
来源:互联网 发布:动易cms 文件类型 编辑:程序博客网 时间:2024/06/05 17:46
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { ListNode* h1 = headA, *h2 = headB; int len1 = 0, len2 = 0; while(h1 != NULL) { len1++; h1 = h1->next; } while(h2 != NULL) { len2++; h2 = h2 ->next; } h1 = headA, h2 = headB; while(len1 < len2) { len2--; h2 = h2->next; } while(len1 > len2) { len1--; h1 = h1->next; } while(h1 != NULL && h2 != NULL) { if(h1 == h2) return h1; else { h1 = h1->next; h2 = h2->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
- easyUI 获取combobox全部数值进行对比方法
- 如何处理.H头文件中的变量
- 十四步实现拥有强大AI的五子棋游戏
- zkw(张昆玮)线段树(单点更新)
- SolrCloud简介
- LeetCode || Intersection of Two Linked Lists
- Python文件操作
- 联诚发(LCF)户外小间距,抢占大舞台
- Zookeeper实践2:命令行及联想
- Android环境搭建 NDK+ADT(免cywgin)
- 心理学上最诡异的23张图片
- 静态成员---计算学生个数
- C# 6.0新特性
- SQL中IN与EXISTS的比较