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:
222222
223223优雅递归:
224224
225+ <!-- tabs:start -->
226+
227+ #### ** Python**
228+
225229``` python
226230# Definition for singly-linked list.
227231# class ListNode:
@@ -243,6 +247,33 @@ class Solution:
243247 return second_node
244248```
245249
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+
246277## 25. K 个一组翻转链表
247278
248279[ 原题链接] ( https://leetcode-cn.com/problems/reverse-nodes-in-k-group/ )
You can’t perform that action at this time.
0 commit comments