File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
docs/data-structure/linked_list Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -222,6 +222,10 @@ class Solution:
222
222
223
223
优雅递归:
224
224
225
+ <!-- tabs:start -->
226
+
227
+ #### ** Python**
228
+
225
229
``` python
226
230
# Definition for singly-linked list.
227
231
# class ListNode:
@@ -243,6 +247,33 @@ class Solution:
243
247
return second_node
244
248
```
245
249
250
+ #### ** Go**
251
+
252
+ ``` go
253
+ /* *
254
+ * Definition for singly-linked list.
255
+ * type ListNode struct {
256
+ * Val int
257
+ * Next *ListNode
258
+ * }
259
+ */
260
+ func swapPairs (head *ListNode ) *ListNode {
261
+ if head == nil || head.Next == nil {
262
+ return head
263
+ }
264
+
265
+ firstNode := head
266
+ secondNode := head.Next
267
+
268
+ firstNode.Next = swapPairs (secondNode.Next )
269
+ secondNode.Next = firstNode
270
+
271
+ return secondNode
272
+ }
273
+ ```
274
+
275
+ <!-- tabs:end -->
276
+
246
277
## 25. K 个一组翻转链表
247
278
248
279
[ 原题链接] ( https://leetcode-cn.com/problems/reverse-nodes-in-k-group/ )
You can’t perform that action at this time.
0 commit comments