reverse a singly linked list for example 1 2 3 4 after reverse 4 3 2 1 iterative solution tn on type head listnode rtype listnode recursive solution tn on type head listnode rtype listnode iterative solution t n o n type head listnode rtype listnode recursive solution t n o n type head listnode rtype listnode
def reverse_list(head):
    
    if not head or not head.next:
        return head
    prev = None
    while head:
        current = head
        head = head.next
        current.next = prev
        prev = current
    return prev






def reverse_list_recursive(head):
    
    if head is None or head.next is None:
        return head
    p = head.next
    head.next = None
    revrest = reverse_list_recursive(p)
    p.next = head
    return revrest