parent
4f7e3d969e
commit
fed1fffac5
|
|
@ -228,7 +228,22 @@ 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: Optional[ListNode]) -> Optional[ListNode]:
|
||||
if not head or not head.next: return head
|
||||
p = self.reverseList(head.next)
|
||||
head.next.next = head
|
||||
head.next = None
|
||||
return p
|
||||
```
|
||||
|
||||
Go:
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue