题目链接:两个链表的第一个公共节点
import java.util.*;
/*
public class ListNode {int val;ListNode next = null;ListNode(int val) {this.val = val;}
}*/
public class Solution {public ListNode FindFirstCommonNode(ListNode head1, ListNode head2) {ListNode p = head1, q = head2;while(p != q){if(p != null) p = p.next;else p = head2;if(q != null) q = q.next;else q = head1;}return q;}
}