标签:practice 节点 ref scribe coder val ranking desc turn
题目链接:
分析:
中序遍历。
/* public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; } } */ public class Solution { private TreeNode node =null; private int pos = 0; TreeNode KthNode(TreeNode pRoot, int k) { if(null == pRoot){ return null; } //左子树 KthNode(pRoot.left,k); //当前节点 pos++; if(pos == k && node == null){ node = pRoot; return node; } //右子树 KthNode(pRoot.right,k); return node; } }
标签:practice 节点 ref scribe coder val ranking desc turn
原文地址:https://www.cnblogs.com/MoonBeautiful/p/13122290.html