Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions reverse-linked-list/dusunax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'''
# 206. Reverse Linked List

iterate through the linked list and reverse the direction of the pointers.

## Time and Space Complexity

```
TC: O(n)
SC: O(1)
```
'''
class Solution:
def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:
prev = None
current = head

while current is not None: # TC: O(n)
next_list_temp = current.next
current.next = prev
prev = current
current = next_list_temp

return prev
Loading