#include <iostream>
#include <vector>
#include <stack>
using namespace std;
/**
* Definition for a binary tree node.
* 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> vc;
stack<TreeNode *> st;
if (!root) return {};
TreeNode* ret = root;
while (ret || !st.empty()) {
while (ret) {
st.push(ret);
ret = ret->left;
}
ret = st.top();
st.pop();
vc.push_back(ret->val);
ret = ret->right;
}
return vc;
}
};