Skip to content

Commit

Permalink
双指针牛逼
Browse files Browse the repository at this point in the history
  • Loading branch information
walkerxiong committed Jul 21, 2021
1 parent 191c871 commit 5740e4c
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions 160.相交链表.go
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5740e4c

Please sign in to comment.