```
class Solution {
public:
int kthSmallest(TreeNode* root, int k) {
vector<int> result;
InOrder(root,result);
return result[k-1];
}
void InOrder(TreeNode* root,vector<int>& result)
{
if(!root)
return;
InOrder(root->left,result);
result.emplace_back(root->val);
InOrder(root->right,result);
}
};
```