题解 | #两个链表的第一个公共结点#
两个链表的第一个公共结点
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 mp:=make(map[*ListNode]bool) for pHead1!=nil{ mp[pHead1]=true pHead1=pHead1.Next } for pHead2!=nil{ if _,ok:=mp[pHead2];ok{ return pHead2 } pHead2=pHead2.Next } return nil }