We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3389f67 commit 5e18608Copy full SHA for 5e18608
problems/0206.翻转链表.md
@@ -143,7 +143,25 @@ class Solution {
143
```
144
145
Python:
146
-
+```python
147
+#双指针
148
+# Definition for singly-linked list.
149
+# class ListNode:
150
+# def __init__(self, val=0, next=None):
151
+# self.val = val
152
+# self.next = next
153
+class Solution:
154
+ def reverseList(self, head: ListNode) -> ListNode:
155
+ cur = head
156
+ pre = None
157
+ while(cur!=None):
158
+ temp = cur.next # 保存一下 cur的下一个节点,因为接下来要改变cur->next
159
+ cur.next = pre #反转
160
+ #更新pre、cur指针
161
+ pre = cur
162
+ cur = temp
163
+ return pre
164
+```
165
166
Go:
167
0 commit comments