refactor: add golang solution to Intersection of Two Linked Lists LCCI

This commit is contained in:
hongyang
2022-06-09 23:24:30 +08:00
parent 87abfa1664
commit 730f58bcce

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
```js