# 160. 相交链表

 1 class Solution {
2 public:
4         set<ListNode*> node_set;
8         }
10             if (node_set.find(headB) != node_set.end()) { //find()没找到，返回 end()
12             }
14         }
15         return NULL;
16     }
17 };

 1 class Solution {
2 public:
6         if (list_A_len > list_B_len) {
8         } else {
10         }
14             }
17         }
18         return NULL;
19     }
20 private:
21     //计算链表长度
23         int len = 0;
25             ++len;
27         }
28         return len;
29     }
30
31     //将长链表指针向后移动，返回对齐后的位置
32     ListNode* forwardLongList(ListNode* long_head, int long_len, int short_len) {
33         int delta = long_len - short_len;
34         while (long_head && delta) {
36             --delta;
37         }
39     }
40 };

 1 int main(int argc, const char * argv[]) {
2     ListNode a1(1);
3     ListNode a2(2);
4     ListNode b1(3);
5     ListNode b2(4);
6     ListNode b3(5);
7     ListNode c1(6);
8     ListNode c2(7);
9     ListNode c3(8);
10     a1.next = &a2;
11     a2.next = &c1;
12     c1.next = &c2;
13     c2.next = &c3;
14     b1.next = &b2;
15     b2.next = &b3;
16     b3.next = &c1;
17
18     Solution solve;
19     ListNode *result = solve.getIntersectionNode(&a1, &b1);
20     cout <<result->val;
21
22     return 0;
23 }
View Code

posted @ 2019-11-09 14:39  0x8023  阅读(...)  评论(... 编辑 收藏