class Solution {
public:
vector<int> inorderTraversal(TreeNode* root) {
vector<int> res;
stack<TreeNode*> st;
while(root||st.size())
{
while(root)
{
st.push(root);
root=root->left;
}
//此时root为空,返回根节点并输出,然后遍历右孩子
//栈一定有元素,两个while循环保证了
root=st.top();
st.pop();
res.push_back(root->val);
root=root->right;
}
return res;
}
};
标签:遍历,res,中序,st,while,二叉树,root,94
From: https://www.cnblogs.com/tangxibomb/p/17418640.html