作业 - 第八周
双指针法求解
/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
Next ListNode
* }
*/
func getIntersectionNode(headA, headB ListNode) ListNode {
pa:=headA
pb:=headB
for pa!=pb{
if pa==nil{
pa=headB
}else{
pa=pa.Next
}
if pb==nil{
pb=headA
}else{
pb=pb.Next
}
}
return pa
}
评论