/**
* 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) {
vector<int> res;
if(!root)
return res;
stack<TreeNode*> stack;
stack.push(root);
while(!stack.empty() || root)
{
while(root)
{
root = root->left;
if(root)
stack.push(root);
}
root = stack.top();
stack.pop();
res.push_back(root->val);
root = root->right;
if(root)
stack.push(root);
}
return res;
}
};