leetcode

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

0094.cpp (520B)


0 class Solution {
1 public:
2 vector<int> inorderTraversal(TreeNode *root) {
3 vector<int> res;
4 stack<TreeNode *> st;
6 while (true) {
7 while (root) {
8 st.push(root);
9 root = root->left;
10 }
12 if (!st.empty()) {
13 root = st.top();
14 st.pop();
15 res.push_back(root->val);
16 root = root->right;
17 } else
18 return res;
19 }
21 return res;
22 }
23 };