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

Commit 24ffed0

Browse files
committed
Feat: update 1669
1 parent da7eded commit 24ffed0

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

‎problems/1669-merge-in-between-linked-lists.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,31 @@ class Solution {
2424
*/
2525
function mergeInBetween($list1, $a, $b, $list2) {
2626
$n = 1;
27+
// 找到第a-1个节点
2728
$left = $list1;
29+
// 找到第b+1个节点
2830
$right = $list1;
29-
$dumyRight = null;
30-
$dumyRight->next = $right;
3131
while ($n <= $b) {
32-
$dumyRight->next = $right->next->next;
3332
if ($n < $a) {
3433
$left = $left->next;
3534
}
3635
$right = $right->next;
37-
3836
$n++;
3937
}
40-
$left->next = $list2;
38+
$right = $right->next;
39+
// 此处结束后,$left 和 $right 分别是 $list1 的前段的尾节点,和后段的头节点。
40+
41+
// 找到 $list2 的尾结点
4142
$cur = $list2;
4243
while ($cur->next) {
4344
$cur = $cur->next;
4445
}
45-
$cur->next = $dumyRight->next;
46+
47+
// 拼接
48+
$left->next = $list2;
49+
$cur->next = $right;
4650
return $list1;
4751
}
48-
}
52+
}
4953

5054
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /