We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent aa1a1ac commit 67c6eb0Copy full SHA for 67c6eb0
0206-reverse-linked-list/0206-reverse-linked-list.py
@@ -0,0 +1,26 @@
1
+# Definition for singly-linked list.
2
+# class ListNode(object):
3
+# def __init__(self, val=0, next=None):
4
+# self.val = val
5
+# self.next = next
6
+class Solution(object):
7
+ def reverseList(self, head):
8
+ """
9
+ :type head: Optional[ListNode]
10
+ :rtype: Optional[ListNode]
11
12
+ temp =[]
13
+ while head:
14
+ temp.append(head.val)
15
+ head = head.next
16
+
17
+ temp = temp[::-1] #Reverse the temp list
18
19
+ myNode = ListNode() #Create the Listnode instance
20
+ current = myNode
21
22
+ for value in temp:
23
+ current.next = ListNode(value)
24
+ current = current.next
25
26
+ return myNode.next
0 commit comments