LeetCode 160. 相交链表
题目链接:
力扣https://leetcode-cn.com/problems/intersection-of-two-linked-lists/
【方法一】用哈希表存其中一条链的节点,在遍历第二条链的时候检查是否在哈希表中即可。
public class Solution {
public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
Set
while(headA != null){
set.add(headA);
headA = headA.next;
}
while(headB != null){
if(set.contains(headB)) return headB;
headB = headB.nex
共有 0 条评论