应用题-链表专题-反转链表

管理员
```python # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: # 示例: 输入: 1->2->3->4->5->NULL 输出: 5->4->3->2->1->NULL def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]: if not head: return None if head and not head.next: return head prv = None cur = head while cur: t = cur.next cur.next = prv prv = cur cur = t return prv ```
评论 0

发表评论 取消回复

Shift+Enter 换行  ·  Enter 发送
还没有评论,来发表第一条吧