/**
* Definition for a binary tree node.
* 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> res;
stack<TreeNode*> s;
TreeNode* curr=root;
while(curr)
{
s.push(curr);
curr=curr->left;
}
while(!s.empty())
{
res.push_back(s.top()->val);
curr=s.top()->right;
s.pop();
while(curr)
{
s.push(curr);
curr=curr->left;
}
}
return res;
}
};
leetcode 94: Binary Tree Inorder Traversal
最新推荐文章于 2021-05-11 10:57:38 发布