class Solution {
private:
int i = 0;
public:
TreeNode* kthNode(TreeNode* root, int k) {
if(root != NULL){
TreeNode *left = NULL, *right = NULL;
if(root->left)
left = kthNode(root->left, k);
i++;
if(i == k)
return root;
if(root->right)
right = kthNode(root->right, k);
return left == NULL ? right : left;
}
}
};