# 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:
if not head or not head.next: return head
left, right = head, head.next
head.next = None
while right:
tmp = right.next
right.next = left
left, right = right, tmp
return left
https://leetcode-cn.com/problems/reverse-linked-list/