Very simple and clear c++ code


#1

/**

  • Definition for binary tree
  • struct TreeNode {
  • int val;
    
  • TreeNode *left;
    
  • TreeNode *right;
    
  • TreeNode(int x) : val(x), left(NULL), right(NULL) {}
    
  • };
    /
    void inorder(TreeNode
    t,vector &v){
    if(t){
    inorder(t->left,v);
    v.push_back(t->val);
    inorder(t->right,v);
    }
    else{
    return;
    }
    }

int Solution::kthsmallest(TreeNode* A, int B) {
TreeNode *t=A;
vector v;
inorder(t,v);

int y=v[B-1];
return y;

}


#2

your soln gave memory limit exceeded.