8000 Feat: 1669 · FX-Max/leetcode@da7eded · GitHub
[go: up one dir, main page]

Skip to content

Commit da7eded

Browse files
committed
Feat: 1669
1 parent 7153efd commit da7eded

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
## 题目
2+
3+
* 1669. 合并两个链表
4+
5+
给你两个链表 list1 和 list2 ,它们包含的元素分别为 n 个和 m 个。
6+
7+
请你将 list1 中下标从 a 到 b 的全部节点都删除,并将list2 接在被删除节点的位置。
8+
9+
## 思路
10+
11+
12+
## 代码
13+
14+
```php
15+
16+
class Solution {
17+
18+
/**
19+
* @param ListNode $list1
20+
* @param Integer $a
21+
* @param Integer $b
22+
* @param ListNode $list2
23+
* @return ListNode
24+
*/
25+
function mergeInBetween($list1, $a, $b, $list2) {
26+
$n = 1;
27+
$left = $list1;
28+
$right = $list1;
29+
$dumyRight = null;
30+
$dumyRight->next = $right;
31+
while ($n <= $b) {
32+
$dumyRight->next = $right->next->next;
33+
if ($n < $a) {
34+
$left = $left->next;
35+
}
36+
$right = $right->next;
37+
38+
$n++;
39+
}
40+
$left->next = $list2;
41+
$cur = $list2;
42+
while ($cur->next) {
43+
$cur = $cur->next;
44+
}
45+
$cur->next = $dumyRight->next;
46+
return $list1;
47+
}
48+
}
49+
50+
```

0 commit comments

Comments
 (0)
0