pull/11/head
yuanguangxin 2 years ago
parent 68d5bbcb06
commit 75d8926232

@ -16,6 +16,7 @@
- [q25_k个一组翻转链表](/src/链表操作/q25_k个一组翻转链表)
- [q61_旋转链表](/src/链表操作/q61_旋转链表)
- [q138_复制带随机指针的链表](/src/链表操作/q138_复制带随机指针的链表)
- [q160_相交链表](/src/链表操作/q160_相交链表)
- [q206_反转链表](/src/链表操作/q206_反转链表)
### 双指针遍历/滑动窗口

@ -16,6 +16,7 @@
- [Question 25 : Reverse Nodes in k-Group](/src/链表操作/q25_k个一组翻转链表)
- [Question 61 : Rotate List](/src/链表操作/q61_旋转链表)
- [Question 138 : Copy List with Random Pointer](/src/链表操作/q138_复制带随机指针的链表)
- [Question 160 : Intersection of Two Linked Lists](/src/链表操作/q160_相交链表)
- [Question 206 : Reverse Linked List](/src/链表操作/q206_反转链表)
### Two Pointers Traversal / Sliding Window

@ -0,0 +1,11 @@
package .q160_;
public class ListNode {
int val;
ListNode next;
ListNode(int x) {
val = x;
next = null;
}
}

@ -0,0 +1,28 @@
package .q160_;
import java.util.HashSet;
import java.util.Set;
/**
*
*
*
*/
public class Solution {
public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
Set<ListNode> visited = new HashSet<>();
ListNode temp = headA;
while (temp != null) {
visited.add(temp);
temp = temp.next;
}
temp = headB;
while (temp != null) {
if (visited.contains(temp)) {
return temp;
}
temp = temp.next;
}
return null;
}
}
Loading…
Cancel
Save