Kth Smallest Element in a BST LeetCode solution in C++
1class Solution {2public:3void findInorder(TreeNode *root, vector<int> &ans) {4if (root == NULL) return;56findInorder(root->left, ans);7ans.push_back(root->val);8findInorder(root->right, ans);9}10int kthSmallest(TreeNode *root, int k) {11vector<int> ans;12findInorder(root, ans);13return ans[k - 1];14}15};