class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
def reverseList_loop(head: ListNode) -> ListNode:
if head is None or head.next is None:
return head
prev = None
curr = head
h = head
while curr:
h = curr
tmp = curr.next
curr.next = prev
prev = curr
curr = tmp
return h