File tree Expand file tree Collapse file tree 1 file changed +9
-12
lines changed Expand file tree Collapse file tree 1 file changed +9
-12
lines changed Original file line number Diff line number Diff line change 1
1
## 题目地址(24. 两两交换链表中的节点)
2
+
2
3
https://leetcode-cn.com/problems/swap-nodes-in-pairs/
3
4
4
5
## 题目描述
5
6
6
-
7
7
给定一个链表,两两交换其中相邻的节点,并返回交换后的链表。
8
8
9
9
你不能只是单纯的改变节点内部的值,而是需要实际的进行节点交换。
10
10
11
11
![ image.png] ( https://assets.leetcode.com/uploads/2020/10/03/swap_ex1.jpg )
12
12
13
13
```
14
-
15
14
示例 1:
16
-
17
-
18
15
输入:head = [1,2,3,4]
19
16
输出:[2,1,4,3]
20
- 示例 2:
21
17
18
+ 示例 2:
22
19
输入:head = []
23
20
输出:[]
24
- 示例 3:
25
21
22
+ 示例 3:
26
23
输入:head = [1]
27
24
输出:[1]
28
-
29
25
30
26
提示:
31
-
32
27
链表中节点的数目在范围 [0, 100] 内
33
28
0 <= Node.val <= 100
34
-
35
29
```
36
30
37
31
## 前置知识
@@ -70,7 +64,9 @@ https://leetcode-cn.com/problems/swap-nodes-in-pairs/
70
64
71
65
## 代码
72
66
73
- * 语言支持:JS,Python3, Go, PHP
67
+ - 语言支持:JS,Python3, Go, PHP
68
+
69
+ JS Code:
74
70
75
71
``` js
76
72
/**
@@ -103,9 +99,10 @@ var swapPairs = function(head) {
103
99
}
104
100
return dummy .next ;
105
101
};
106
-
107
102
```
108
- Python3 Code:
103
+
104
+ Python Code:
105
+
109
106
``` python
110
107
class Solution :
111
108
def swapPairs (self , head : ListNode) -> ListNode:
You can’t perform that action at this time.
0 commit comments