Skip to content

Commit

Permalink
添加 0206.翻转链表 python3版本
Browse files Browse the repository at this point in the history
  • Loading branch information
morningsky committed May 30, 2021
1 parent 3389f67 commit 5e18608
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion problems/0206.翻转链表.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,25 @@ class Solution {
```

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:

Expand Down

0 comments on commit 5e18608

Please sign in to comment.