leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0589.cpp (472B)


0 class Solution {
1 public:
2 vector<int> preorder(Node *root) {
3 if (!root) return {};
4 vector<int> res;
5 stack<Node *> st;
6 st.push(root);
7 while (!st.empty()) {
8 Node *root = st.top();
9 st.pop();
10 res.push_back(root->val);
11 reverse(root->children.begin(), root->children.end());
12 for (Node *c : root->children)
13 st.push(c);
14 }
15 return res;
16 }
17 };