个人思路:
笨蛋做法,但是好用
代码如下
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) {
* val = x;
* next = null;
* }
* }
*/
public class Solution {
public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
Set set = new HashSet();
ListNode temp = headA;
while(temp != null) {
set.add(temp);
temp = temp.next;
}
temp = headB;
while(temp != null) {
if(set.contains(temp)){
return temp;
}
temp = temp.next;
}
return null;
}
}