题解 | #两个链表的第一个公共结点# | Golang
两个链表的第一个公共结点
https://www.nowcoder.com/practice/6ab1d9a29e88450685099d45c9e31e46
package main
import . "nc_tools"
/*
* type ListNode struct{
* Val int
* Next *ListNode
* }
*/
/**
*
* @param pHead1 ListNode类
* @param pHead2 ListNode类
* @return ListNode类
*/
func FindFirstCommonNode( pHead1 *ListNode , pHead2 *ListNode ) *ListNode {
curA, curB := pHead1, pHead2
for curA != curB {
if curA == nil {
curA = pHead2
} else {
curA = curA.Next
}
if curB == nil {
curB = pHead1
} else {
curB = curB.Next
}
}
return curA
}

