leetcode 日经贴,Cpp code -Intersection of Two Linked Lists
来源:互联网 发布:东方财富mac上线 编辑:程序博客网 时间:2024/06/06 17:44
Intersection of Two Linked Lists
/** * 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 *ca = headA, *cb = headB; int len1 = 0, len2 = 0; while (ca && ca->next) { ++len1; ca = ca->next; } while (cb && cb->next) { ++len2; cb = cb->next; } if (!ca || !cb || ca != cb) { return NULL; } ca = headA; cb = headB; while (len1 > len2) { ca = ca->next; --len1; } while (len2 > len1) { cb = cb->next; --len2; } while (ca != cb) { ca = ca->next; cb = cb->next; } return ca; }};
0 0
- leetcode 日经贴,Cpp code -Intersection of Two Linked Lists
- Leetcode 160. Intersection of Two Linked Lists (Easy) (cpp)
- [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
- 软件随想录 卷1
- android ORM框架--greenDao简介
- [leetcode] Number of Islands
- PHP中cookie和session学习
- 浅谈java反射问题
- leetcode 日经贴,Cpp code -Intersection of Two Linked Lists
- unity3d 移动平台使用的网络环境判断(是否联网、是否wifi)
- 四大因素决定 浅析iOS为什么比安卓流畅
- ubuntu安装、配置JDK
- Default SSH Config
- LinkedHashMap和HashMap的比较使用
- linux虚拟内存
- linux应用开发-coredump
- 【Java二十周年】