mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-06 23:28:29 +08:00
@ -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:
|
||||
|
||||
|
Reference in New Issue
Block a user