forked from pezy/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.h
More file actions
32 lines (30 loc) · 691 Bytes
/
solution.h
File metadata and controls
32 lines (30 loc) · 691 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <vector>
#include <stack>
using std::vector; using std::stack;
struct TreeNode {
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
class Solution {
public:
vector<int> inorderTraversal(TreeNode *root) {
vector<int> ret;
for (stack<TreeNode *> s; !s.empty() || root; )
{
if (root)
{
s.push(root);
root = root->left;
}
else
{
root = s.top(); s.pop();
ret.push_back(root->val);
root = root->right;
}
}
return ret;
}
};