@@ -0,0 +1,1035 @@
+%22%22%22%0AReverse a singly linked list.%0A%0AExample:%0A%0AInput: 1-%3E2-%3E3-%3E4-%3E5-%3ENULL%0AOutput: 5-%3E4-%3E3-%3E2-%3E1-%3ENULL%0AFollow up:%0A%0AA linked list can be reversed either iteratively or recursively. Could you implement both?%0A%22%22%22%0A%0A# Definition for singly-linked list.%0A# class ListNode:%0A#     def __init__(self, x):%0A#         self.val = x%0A#         self.next = None%0A%0Aclass Solution:%0A    def reverseList(self, head: ListNode) -%3E ListNode:%0A        # This is the moving head pointer solution%0A        if not head:%0A            return None%0A%0A        next = None%0A        new_head = head%0A        while head.next:%0A            next = head.next%0A            head.next = next.next%0A            next.next = new_head%0A            new_head = next%0A        return new_head%0A%0A    def reverseList(self, head: ListNode) -%3E ListNode:%0A        # This is the double pointer solution%0A        prev = None%0A        current = head%0A        while current:%0A            temp = current.next%0A            current.next = prev%0A            prev = current%0A            current = temp%0A%0A        return prev%0A

Add 206