We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent cb94794 commit 4a475c3Copy full SHA for 4a475c3
src/0101-0200/160 - Intersection of Two Linked Lists/intersection_of_two_linked_lists.go
@@ -0,0 +1,32 @@
1
+package main
2
+
3
+// Definition for singly-linked list.
4
+type ListNode struct {
5
+ Val int
6
+ Next *ListNode
7
+}
8
9
+// https://leetcode.com/problems/intersection-of-two-linked-lists/solutions/49785/java-solution-without-knowing-the-difference-in-len/
10
+func getIntersectionNode(headA, headB *ListNode) *ListNode {
11
+ if headA == nil || headB == nil {
12
+ return nil
13
+ }
14
15
+ a, b := headA, headB
16
17
+ for a != b {
18
+ if a == nil {
19
+ a = headB
20
+ } else {
21
+ a = a.Next
22
23
24
+ if b == nil {
25
+ b = headA
26
27
+ b = b.Next
28
29
30
31
+ return a
32
0 commit comments