/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
int kthSmallest(TreeNode* root, int k) {
vector<int> v;
inOrder(root, v);
return v[k - 1];
}
private:
void inOrder(TreeNode* root, vector<int>& v) {
if (root != NULL)
{
inOrder(root->left, v);
v.push_back(root->val);
inOrder(root->right, v);
}
}
};