Recursive C++ approach


#1
`

setst;

void check(TreeNode* root, int a){
st.insert(root->val);
if(root->left) check(root->left,a);
if(root->right) check(root->right,a);
}

int Solution::kthsmallest(TreeNode* A, int B) {
st.clear();
if(A)
check(A,B);
int c=1;
for(auto itr=st.begin();itr!=st.end();itr++){
if(c==B) return *itr;
c++;
}

}

`