/*function ListNode(x){
this.val = x;
this.next = null;
}*/
function FindFirstCommonNode(pHead1, pHead2)
{
// write code here
while(pHead1){
if(pHead1.flag==true){
return pHead1;
}
pHead1.flag=true;
pHead1=pHead1.next;
}
while(pHead2){
if(pHead2.flag==true){
return pHead2;
}
pHead2.flag=true;
pHead2=pHead2.next;
}
return null
}
module.exports = {
FindFirstCommonNode : FindFirstCommonNode
};
老规矩,遍历过的节点做标记,如果遇到了遍历过的节点,那么就是入口直接返回
如果都遍历完了就为null



京公网安备 11010502036488号