diff --git a/go/0160-intersection-of-two-linked-lists.go b/go/0160-intersection-of-two-linked-lists.go new file mode 100644 index 000000000..2cf236064 --- /dev/null +++ b/go/0160-intersection-of-two-linked-lists.go @@ -0,0 +1,23 @@ +/** + * Definition for singly-linked list. + * type ListNode struct { + * Val int + * Next *ListNode + * } + */ +func getIntersectionNode(headA, headB *ListNode) *ListNode { + a, b := headA, headB + for a != b { + if a == nil { + a = headB + } else { + a = a.Next + } + if b == nil { + b = headA + } else { + b = b.Next + } + } + return a +} \ No newline at end of file