用两个栈来存储了一下各个节点,分别弹栈来把重复的去掉......
public ListNode FindFirstCommonNode(ListNode pHead1, ListNode pHead2) {
if(pHead1==null||pHead2==null)return null;
Stack<listnode> stack1 = new Stack<>();
Stack<listnode> stack2 = new Stack<>();
while(pHead1!=null) {
stack1.push(pHead1);
pHead1=pHead1.next;
}
while(pHead2!=null) {
stack2.push(pHead2);
pHead2=pHead2.next;
}
ListNode res = null;
while(!stack1.isEmpty()&&!stack2.isEmpty()&&stack1.peek()==stack2.peek()) {
res =stack1.pop();
stack2.pop();
}
return res;
}</listnode></listnode>