//用search计算左子树的节点个数,加上根节点本身若为k则输出,否则
//(1)若k大于目前个数,则k-左子树节点个数,再计算右子树
//(2)若k小于目前个数,则直接计算左子树
/**
* 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 {
private:
int result=0;
int search(TreeNode* root)
{
if(root==NULL)
return 0;
return 1+search(root->left)+search(root->right);
}
public:
int kthSmallest(TreeNode* root, int k) {
int result;
int count=search(root->left)+1;
if(count==k)return root->val;
else if(count>k)kthSmallest(root->left,k);
else if(count<k)kthSmallest(root->right,k-count);
}
};