class Solution {
public:
vector<int> inorderTraversal(TreeNode *root) {
vector<int>result;
stack<TreeNode*>st;
TreeNode*p=root;
while(!st.empty()||p)
{
if(p)
{
st.push(p),p=p->left;
}
else
{
p=st.top();
st.pop();
result.push_back(p->val);
p=p->right;
}
}
return result;
}
};
网友评论