* struct TreeNode {
 *	int val;
 *	struct TreeNode *left;
 *	struct TreeNode *right;
 *	TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 * };
 */
class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param proot TreeNode类 
     * @param k int整型 
     * @return int整型
     */
    int count=0;
    int result=-1;
    int KthNode(TreeNode* proot, int k) {
        if(k<=0||proot==NULL){
            return -1;
        }
        else{ 
            //采用二叉搜索树的中序遍历算法
            if(proot->left!=NULL){
                KthNode(proot->left,k);
            }
            //每次中间节点实现计数
            count+=1;
            if(count==k){
              return  result=proot->val;
            }
            if(proot->right!=NULL){
                 KthNode(proot->right,k);
            }
            return result;
        }
        // write code here
    }
};