//解题思路:如果有两个节点是一样的,那这两个链表从这个节点开始,后面全部是一样的。 public ListNode FindFirstCommonNode(ListNode pHead1, ListNode pHead2) { if(pHead1==null||pHead2==null){ return null; } Stack<ListNode> stack1=new Stack<ListNode>(); Stack<ListNode> stack2=new Stack<ListNode>(); while(pHead1!=null){ stack1.push(pHead1); pHead1=pHead1.next; } while(pHead2!=null){ stack2.push(pHead2); pHead2=pHead2.next; } //同时开始抛出 ListNode result=null; while(!stack1.empty()&&!stack2.empty()&&stack1.peek()==stack2.peek()){ stack1.pop(); result=stack2.pop(); } return result; }