36、两个链表的第一个公共结点

一、题目

输入两个链表,找出它们的第一个公共结点。

二、解法

 1 public class Solution {
 2    public ListNode FindFirstCommonNode(ListNode pHead1, ListNode pHead2) {
 3         ListNode p1 = pHead1;
 4         ListNode p2 = pHead2;
 5         while(p1 != p2){
 6             p1 = (p1 == null ? pHead2 : p1.next);
 7             p2 = (p2 == null ? pHead1 : p2.next);
 8         }
 9         return p2;
10     }
11 }
原文地址:https://www.cnblogs.com/fankongkong/p/7456623.html