lurenaa的博客

😂

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Solution {
public:
vector<int> preorderTraversal(TreeNode* root) {
vector<int> vec;
stack<TreeNode* > stk;
if(root)
stk.push(root);
while(stk.size()) {
auto top = stk.top();
stk.pop();
if(top->right) {
stk.push(top->right);
}
vec.push_back(top->val);
if(top->left) {
stk.push(top->left);
}

}
return vec;
}
};

Accepted

68/68 cases passed (0 ms)

Your runtime beats 100 % of cpp submissions

Your memory usage beats 13.44 % of cpp submissions (9.4 MB)