blob: a677d279b3fb8a13dc78d8935723095c2882970c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#include "leetcode.h"
class Solution {
public:
vector<int> inorderTraversal(TreeNode *root) {
vector<int> ans;
stack<TreeNode *> s;
TreeNode *curr = root;
while (curr || !s.empty()) {
while (curr) {
s.push(curr);
curr = curr->left;
}
curr = s.top();
s.pop();
ans.push_back(curr->val);
curr = curr->right;
}
return ans;
}
};
int main() { Solution obj; }
|