-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreverse-linked-list.py
More file actions
30 lines (25 loc) · 838 Bytes
/
reverse-linked-list.py
File metadata and controls
30 lines (25 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
# Ah! for some reason, I took a really long time to wrap my head around this solution
# video explanation at : https://www.youtube.com/watch?v=PJzgqT2Ujek
class Solution(object):
def reverseList(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
self.head = head
current = self.head
previous = None
next = None
while current:
next = current.next
current.next = previous
previous = current
current = next
self.head = previous
return self.head
# This is one of the solutions for which I would need lists generated by my test infrastructure code