/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
*/
class Solution {
public:
vector<int> inorderTraversal(TreeNode* root)
{
stack<TreeNode*>stack;
vector<int>res;
while(root||!stack.empty())
{
while(root)
{
stack.push(root);
root=root->left;
}
root=stack.top();
res.push_back(root->val);
stack.pop();
root=root->right;
}
return res;
}
};
05-27
368
01-12
311