题解 | #两个链表的第一个公共结点#
两个链表的第一个公共结点
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 {
// write code here
first := pHead1
second := pHead2
for i := 0;;i++ {
if first == second {
return first
}
if first == nil {
first = pHead2
}else {
first = first.Next
}
if second == nil {
second = pHead1
}else {
second = second.Next
}
}
}
查看13道真题和解析