Merge pull request #1457 from LIU-HONGYANG/hongyangliu.add-solution

refactor: add golang solution to Intersection of Two Linked Lists LCCI
This commit is contained in:
程序员Carl
2022-07-18 09:14:04 +08:00
committed by GitHub

View File

@ -208,6 +208,29 @@ func getIntersectionNode(headA, headB *ListNode) *ListNode {
} }
``` ```
双指针
```go
func getIntersectionNode(headA, headB *ListNode) *ListNode {
l1,l2 := headA, headB
for l1 != l2 {
if l1 != nil {
l1 = l1.Next
} else {
l1 = headB
}
if l2 != nil {
l2 = l2.Next
} else {
l2 = headA
}
}
return l1
}
```
### javaScript ### javaScript
```js ```js