题解 | #两个链表的第一个公共结点#
两个链表的第一个公共结点
http://www.nowcoder.com/practice/6ab1d9a29e88450685099d45c9e31e46
思路:双重判断,暴力破解,结果直接返回即可
public class ListNode {
int val;
ListNode next = null;
ListNode(int val) {
this.val = val;
}
}*/
public class Solution {
public ListNode FindFirstCommonNode(ListNode pHead1, ListNode pHead2) {
ListNode a=new ListNode(-1);
a.next=pHead1;
while (a!=null){
ListNode h=new ListNode(-1);
h.next=pHead2;
while (h!=null){
if(h.next==a.next){
return a.next;
}
h=h.next;
}
a=a.next;
}
return null;
}
}