Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

160. 相交链表 #61

Open
Open
Labels
@Geekhyt

Description

@Geekhyt

原题链接

双指针

  1. 借助双指针分别遍历链表 A 和 B。
  2. 遍历完自己后再将头指针指向另一个链表头部,继续遍历。
  3. 如果存在交点,则一定会相遇。
constgetIntersectionNode=function(headA,headB){if(headA===null||headB===null){returnnull}letpA=headA,pB=headBwhile(pA!==pB){pA=pA===null ?headB :pA.nextpB=pB===null ?headA :pB.next}returnpA}
  • 时间复杂度:O(m + n)
  • 空间复杂度:O(1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp