题解 | #二叉搜索树的第k个节点(递归中序遍历)#
二叉搜索树的第k个节点
https://www.nowcoder.com/practice/57aa0bab91884a10b5136ca2c087f8ff
import java.util.*; public class Solution { int count = 0; int result = -1; public int KthNode (TreeNode proot, int k) { // write code here if (proot!=null){ // 遍历左子树 KthNode(proot.left,k); // 处理当前节点 count++; if (count==k) result = proot.val; // 遍历右子树 KthNode(proot.right,k); } return result; } }