Easiest C++ Solution Inorder


#1
vector<int> v;

void inorder(TreeNode* root, int k)
{
if(root==NULL) return;
inorder(root->left, k);
v.push_back(root->val);
if(v.size()>=k) return;
inorder(root->right, k);
}

int Solution::kthsmallest(TreeNode* root, int k) {
v.clear();
if(root==NULL) return 0;
inorder(root, k);
return v[k-1];
}