1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| class ListNode:
def __init__(self, x):
self.val = x
self.next = None
def reverseList(head: ListNode) -> ListNode:
if not head or not head.next:
return head
pre = None
cur = head
while cur:
tmp = cur.next
cur.next = pre
pre = cur
cur = tmp
return pre
|