leetcode

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

0590.cpp (447B)


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