Skip to content

Commit 4b1f411

Browse files
committed
剑指Offer–037-两个链表的第一个公共结点--http://blog.csdn.net/gatieme/article/details/51330871
1 parent 1faeedc commit 4b1f411

6 files changed

Lines changed: 39 additions & 15 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#include <iostream>
22

3+
34
using namespace std;
45

6+
57
// 调试开关
68
#define __tmain main
79

@@ -52,7 +54,7 @@ class Solution
5254
if(left == right)
5355
{
5456
break;
55-
}
57+
}
5658
}
5759
if(left == right)
5860
{
@@ -64,6 +66,9 @@ class Solution
6466
}
6567
};
6668

69+
70+
71+
6772
int __tmain( )
6873
{
6974
ListNode common[2];
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#include <iostream>
22

3+
34
using namespace std;
45

6+
7+
58
// 调试开关
69
#define __tmain main
710

@@ -16,17 +19,18 @@ using namespace std;
1619
#endif // __tmain
1720

1821

22+
23+
1924
#ifdef __tmain
2025

2126
struct ListNode
2227
{
2328
public :
2429
int val;
2530
struct ListNode *next;
26-
2731
};
28-
#endif
2932

33+
#endif // #endif __tmain
3034

3135
class Solution
3236
{
@@ -79,7 +83,7 @@ class Solution
7983

8084
return ((left == right) ? left : NULL);
8185
}
82-
86+
8387
int GetListLength(ListNode *head)
8488
{
8589
ListNode *node = head;
@@ -88,7 +92,7 @@ class Solution
8892
{
8993
length++;
9094
node = node->next;
91-
}
95+
}
9296

9397
return length;
9498
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#include <iostream>
22
#include <stack>
33

4+
45
using namespace std;
56

7+
68
// 调试开关
79
#define __tmain main
810

@@ -26,7 +28,9 @@ public :
2628
struct ListNode *next;
2729

2830
};
29-
#endif
31+
32+
#endif // #endif __tmain
33+
3034

3135

3236
class Solution
@@ -36,7 +40,7 @@ class Solution
3640
{
3741
ListNode *left = leftHead;
3842
ListNode *right = rightHead;
39-
43+
4044
stack<ListNode *> leftStack;
4145
stack<ListNode *> rightStack;
4246

@@ -61,9 +65,9 @@ class Solution
6165
{
6266
left = leftStack.top( );
6367
right = rightStack.top( );
64-
68+
6569
debug <<left->val <<", " <<right->val <<endl;
66-
70+
6771
/// 不相同的元素就是合并的前一个结点
6872
if(left != right)
6973
{
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#include <iostream>
22

3+
34
using namespace std;
45

6+
7+
58
// µ÷ÊÔ¿ª¹Ø
69
#define __tmain main
710

@@ -16,6 +19,8 @@ using namespace std;
1619
#endif // __tmain
1720

1821

22+
23+
1924
#ifdef __tmain
2025

2126
struct ListNode
@@ -25,7 +30,9 @@ public :
2530
struct ListNode *next;
2631

2732
};
28-
#endif
33+
34+
35+
#endif // #endif __tmain
2936

3037

3138
class Solution
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#include <iostream>
22
#include <map>
33

4+
45
using namespace std;
56

7+
68
// µ÷ÊÔ¿ª¹Ø
79
#define __tmain main
810

@@ -26,7 +28,9 @@ public :
2628
struct ListNode *next;
2729

2830
};
29-
#endif
31+
32+
33+
#endif // #endif __tmain
3034

3135

3236
class Solution
@@ -35,14 +39,14 @@ class Solution
3539
ListNode* FindFirstCommonNode(ListNode *leftHead, ListNode *rightHead)
3640
{
3741
unordered_map<ListNode*, bool> umap;
38-
42+
3943
ListNode* left = leftHead;
4044
while (left != NULL)
4145
{
4246
umap.insert(make_pair(left, 1 ));
4347
left = left->next;
4448
}
45-
49+
4650
ListNode* right = rightHead;
4751
while (right)
4852
{

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ COMMIT_33="剑指Offer--033-把数组排成最小的数--http://blog.csdn.net/ga
3434
COMMIT_34="剑指Offer--034-丑数--http://blog.csdn.net/gatieme/article/details/51308037"
3535
COMMIT_35="剑指Offer--035-第一个只出现一次的字符位置--http://blog.csdn.net/gatieme/article/details/51319158"
3636
COMMIT_36="剑指Offer--036-数组中的逆序对--http://blog.csdn.net/gatieme/article/details/51326994"
37-
COMMIT_37=""
37+
COMMIT_37="剑指Offer–037-两个链表的第一个公共结点--http://blog.csdn.net/gatieme/article/details/51330871"
3838

3939
RETURN_TOP ="<br>**您也可以选择[回到目录-剑指Offer--题集目录索引](http://blog.csdn.net/gatieme/article/details/51916802)**"
4040

4141

4242

43-
GITHUB_COMMIT=$(COMMIT_36)
43+
GITHUB_COMMIT=$(COMMIT_37)
4444

4545

4646
all:github

0 commit comments

Comments
 (0)