Skip to content

Commit af6e2f7

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

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
// linked list
5+
class Solution {
6+
public:
7+
vector<int> toArray(Node *node){
8+
for (; node->prev; node = node->prev);
9+
vector<int> result;
10+
for (; node; node = node->next) {
11+
result.emplace_back(node->val);
12+
}
13+
return result;
14+
}
15+
};

0 commit comments

Comments
 (0)