#TIme Complexity: O(N)
#Space Complexity: O(1)


# Definition for singly-linked list.
# class ListNode(object):
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution(object):
    def reverseList(self, head):
        """
        :type head: ListNode
        :rtype: ListNode
        """
        if head ==None:
            return None
        prev = None
        curr = head
        fast = head.next
        
        while(fast!=None):
            curr.next = prev
            prev = curr
            curr = fast
            fast = fast.next 
        curr.next = prev
        return curr