-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathgetIntersectionNode_test.go
More file actions
65 lines (62 loc) · 989 Bytes
/
getIntersectionNode_test.go
File metadata and controls
65 lines (62 loc) · 989 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package leet_code
import (
"fmt"
"testing"
)
//两个链表的第一个公共节点
func getIntersectionNode(headA, headB *ListNode) *ListNode {
mapListNode := make(map[ListNode]*ListNode)
for headA != nil {
mapListNode[*headA] = headA
headA = headA.Next
}
for headB != nil {
if mapListNode[*headB] == headB {
return headB
}
headB = headB.Next
}
return nil
}
func Test_getIntersectionNode(t *testing.T) {
data := &ListNode{
Val: 4,
Next: &ListNode{
Val: 1,
Next: &ListNode{
Val: 8,
Next: &ListNode{
Val: 4,
Next: &ListNode{
Val: 5,
Next: nil,
},
},
},
},
}
datab := &ListNode{
Val: 5,
Next: &ListNode{
Val: 0,
Next: &ListNode{
Val: 1,
Next: &ListNode{
Val: 8,
Next: &ListNode{
Val: 4,
Next: &ListNode{
Val: 5,
Next: nil,
},
},
},
},
},
}
d := getIntersectionNode(data, datab)
if d != nil {
fmt.Print(d.Val)
t.Log(d.Val)
}
}