Skip to content

Commit e6e6966

Browse files
authored
Create convert-doubly-linked-list-to-array-ii.py
1 parent af6e2f7 commit e6e6966

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
# linked list
5+
class Solution:
6+
def toArray(self, node):
7+
"""
8+
:type head: Node
9+
:rtype: List[int]
10+
"""
11+
while node.prev:
12+
node = node.prev
13+
result = []
14+
while node:
15+
result.append(node.val)
16+
node = node.next
17+
return result

0 commit comments

Comments
 (0)