//the key is to use a stack smartly
class Solution {
public:
vector<int> inorderTraversal(TreeNode *root) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
//if(root==NULL)
//return NULL;
stack<TreeNode*> s;
vector<int> v;
v.clear();
TreeNode* np=root;
while(1){
while(np){
s.push(np);
np=np->left;
}
if(s.empty())
break;
TreeNode* tmp=s.top();
s.pop();
v.push_back(tmp->val);
np=tmp->right;
}
return v;
}
Leetcode: Binary Tree Inorder Traversal
