leetcode 160. Intersection of Two Linked Lists
来源:互联网 发布:吴闲云水浒知乎 编辑:程序博客网 时间:2024/05/22 05:26
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: int back(ListNode*head){ int len = 0; while(head!=NULL){ len++; head = head->next; } return len; } ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { int len1 = back(headA),len2 = back(headB); ListNode*a=headA,*b=headB; if(len1 > len2){ while(len2 < len1){ a=a->next; len2++; } } else { while(len1 < len2){ b=b->next; len1++; } } while(a != b && a != NULL){ a = a->next; b = b->next; } return a; }};
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
- Linux进程之task_struct结构体
- 简单的学生管理系统
- ToStringBuilder学习(四):readResolve()方法与序列化
- poj 2485
- codeforces AIM Tech Round3
- leetcode 160. Intersection of Two Linked Lists
- 大数据框架 Hadoop 和 Spark 的异同
- 根据Dictionary KEY 自动生成属性
- 渗透测试 2 of 9
- Nosql Mongodb 并发控制之乐观锁
- NYOJ 975 关于521
- 内存结构分析学习笔记
- AppCan_4 IDE 开发流程之新建项目同步到线上
- 可重入锁和读写锁的源码分析