LC94 Binary Tree Inorder Travers
2020-09-02 本文已影响0人
Rookie118
本题链接: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;
}
};
时间复杂度:
空间复杂度: