Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

面试题 02.07. 链表相交 这题可以用双指针无需计算链表长度 #1

Closed
wuzheng228 opened this issue Oct 23, 2020 · 0 comments

Comments

@wuzheng228
Copy link

通过交换指针位置来让指针达到同一个位置

public class Solution {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if (headA == null || headB == null) return null;
        ListNode pA = headA;
        ListNode pB = headB;
        while (true) {
            if (pA == null && pB == null) return null;
            if (pA == null) {
                pA = headB;
            }
            if (pB == null) {
                pB = headA;
            }
            if (pA == pB) return pB;
            pA = pA.next;
            pB = pB.next;
        }
    }
}
youngyangyang04 pushed a commit that referenced this issue Mar 9, 2021
Update 数组理论基础.md
youngyangyang04 pushed a commit that referenced this issue May 12, 2021
youngyangyang04 pushed a commit that referenced this issue May 13, 2021
fusunx pushed a commit to fusunx/leetcode-master that referenced this issue May 16, 2021
fusunx pushed a commit to fusunx/leetcode-master that referenced this issue May 16, 2021
fusunx pushed a commit to fusunx/leetcode-master that referenced this issue May 16, 2021
youngyangyang04 pushed a commit that referenced this issue Jul 29, 2021
youngyangyang04 pushed a commit that referenced this issue Aug 20, 2021
youngyangyang04 pushed a commit that referenced this issue Feb 9, 2022
更新 背包问题理论基础完全背包.md Java版本
youngyangyang04 pushed a commit that referenced this issue Mar 24, 2022
youngyangyang04 pushed a commit that referenced this issue May 8, 2022
Update 0093.复原IP地址.md (优化剪枝)
youngyangyang04 pushed a commit that referenced this issue Jul 8, 2022
添加(0209.长度最小的子数组.md):增加 C# 版本
youngyangyang04 pushed a commit that referenced this issue Jul 14, 2022
Update 0101.对称二叉树.md level order traversal
youngyangyang04 pushed a commit that referenced this issue Jul 22, 2022
youngyangyang04 pushed a commit that referenced this issue Jan 3, 2023
youngyangyang04 pushed a commit that referenced this issue Feb 28, 2023
修正了python版本的空间复杂度的描述
youngyangyang04 pushed a commit that referenced this issue May 1, 2023
Update 0647.回文子串.md
youngyangyang04 pushed a commit that referenced this issue Aug 22, 2023
新增python3 DFS解法, Leetcode 130 被包围的区域
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant