Simple C++ solution using stack


#1

vector Solution::inorderTraversal(TreeNode* A) {

stack<TreeNode *> s;
vector<int> ans;
TreeNode* root = A;
while(true){
    
    
    while(root){
        s.push(root);
        root = root->left;
    }
    
    if(s.empty()){
        break;
    }
    
    root = s.top();
    s.pop();
    ans.push_back(root->val);
    root = root->right;
    
}
return ans;

}


#3

@ankit-chand , this is how i did it