/**
* Definition for binary tree
* 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> ret;
if(0==root) return ret;
stack<TreeNode *> helpStack;
TreeNode *pNode=root;
while(!helpStack.empty() || pNode)
{
if(pNode)
{
helpStack.push(pNode);
pNode=pNode->left;
}
else
{
pNode=helpStack.top();
ret.push_back(pNode->val);
pNode=pNode->right;
helpStack.pop();
}
}
return ret;
}
};
Binary Tree Inorder Traversal
最新推荐文章于 2022-03-31 17:31:26 发布