From 5740e4ca58edcd0ba66672b67ae2f498c4f6003f Mon Sep 17 00:00:00 2001 From: gbabyX Date: Wed, 21 Jul 2021 17:42:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=8C=E6=8C=87=E9=92=88=E7=89=9B=E9=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...70\344\272\244\351\223\276\350\241\250.go" | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 "160.\347\233\270\344\272\244\351\223\276\350\241\250.go" diff --git "a/160.\347\233\270\344\272\244\351\223\276\350\241\250.go" "b/160.\347\233\270\344\272\244\351\223\276\350\241\250.go" new file mode 100644 index 0000000..1c5b506 --- /dev/null +++ "b/160.\347\233\270\344\272\244\351\223\276\350\241\250.go" @@ -0,0 +1,36 @@ +/* + * @lc app=leetcode.cn id=160 lang=golang + * + * [160] 相交链表 + */ + +// @lc code=start +/** + * Definition for singly-linked list. + * type ListNode struct { + * Val int + * Next *ListNode + * } + */ +func getIntersectionNode(headA, headB *ListNode) *ListNode { + if headA == nil || headB == nil { + return nil + } + 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 +} + +// @lc code=end +