mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 15:45:40 +08:00
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:
@ -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
|
||||
|
||||
```js
|
||||
|
Reference in New Issue
Block a user