Merge pull request #426 from borninfreedom/master

update反转链表:添加python递归法的代码
This commit is contained in:
程序员Carl
2021-06-23 09:40:06 +08:00
committed by GitHub

View File

@ -142,7 +142,7 @@ class Solution {
}
```
Python
Python迭代法
```python
#双指针
# Definition for singly-linked list.
@ -163,6 +163,32 @@ class Solution:
return pre
```
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:
def reverse(pre,cur):
if not cur:
return pre
tmp = cur.next
cur.next = pre
return reverse(cur,tmp)
return reverse(None,head)
```
Go
```go