[go: nahoru, domu]

Skip to content

Commit

Permalink
Update 01.Linked-List-Two-Pointers.md
Browse files Browse the repository at this point in the history
  • Loading branch information
itcharge committed Jan 14, 2022
1 parent 31bb28f commit c955ab2
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

- 使用两个指针 `slow``fast``slow``fast` 都指向链表的头节点,即:`slow = head``fast = head`
- 先将快指针向右移动 `n` 步。然后再同时向右移动快、慢指针。
- 等到快指针移动到链表尾部(即 `fast == Node`)时跳出循环体。
- 等到快指针移动到链表尾部(即 `fast == None`)时跳出循环体。

### 2.2 起点不一致的快慢指针伪代码模板

Expand Down Expand Up @@ -117,7 +117,7 @@ while fast and fast.next:

- 使用两个指针 `slow``fast``slow``fast` 都指向链表的头节点。
- 在循环体中将快、慢指针同时向右移动。其中慢指针每次移动 `1` 步,即 `slow = slow.next`。快指针每次移动 `2` 步,即 `fast = fast.next.next`
- 等到快指针移动到链表尾部(即 `fast == Node`)时跳出循环体,此时 `slow` 指向链表中间位置。
- 等到快指针移动到链表尾部(即 `fast == None`)时跳出循环体,此时 `slow` 指向链表中间位置。
- 返回 `slow` 指针。

#### 3.4.4 代码
Expand Down

0 comments on commit c955ab2

Please sign in to comment.