添加 0206.翻转链表 python3版本

This commit is contained in:
evanlai
2021-05-30 14:10:11 +08:00
parent 3389f6799c
commit 5e1860876b

View File

@ -143,7 +143,25 @@ class Solution {
``` ```
Python Python
```python
#双指针
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def reverseList(self, head: ListNode) -> ListNode:
cur = head
pre = None
while(cur!=None):
temp = cur.next # 保存一下 cur的下一个节点因为接下来要改变cur->next
cur.next = pre #反转
#更新pre、cur指针
pre = cur
cur = temp
return pre
```
Go Go