本题链接:Binary Tree Inorder Traversal
本题标签:Tree, Hash Table, Stack
本题难度:
英文题目 中文题目方案1:
class Solution {
public:
vector<int> inorderTraversal(TreeNode* root) {
vector<int> res;
stack<TreeNode*> stk;
TreeNode *cur = root;
while(cur != NULL || stk.size())
{
while(cur != NULL)
{
stk.push(cur);
cur = cur->left;
}
cur = stk.top();
res.push_back(cur->val);
stk.pop();
cur = cur->right;
}
return res;
}
};
时间复杂度:
空间复杂度:
网友评论