import ListNodeInfo.ListNode;import java.util.HashSet;
import java.util.Set;public class Problem_160_IntersectionOfTwoLinkedList {//双指针方法 public ListNode getIntersectionListNode(ListNode headA, ListNode headB){if(headA == null || headB == null) return null;ListNode a = headA;ListNode b = headB;while (a != b){a = a == null ? headB : a.next;b = b == null ? headA : b.next;}return a;}//利用set方法public ListNode getIntersectionListNode1(ListNode headA, ListNode headB){if(headA == null || headB == null)return null;Set<ListNode> set = new HashSet<>();while (headA != null){set.add(headA);headA = headA.next;}while (headB != null){if(set.contains(headB))return headB;headB = headB.next;}return null;}
}