题解 | #按之字形顺序打印二叉树#

二叉搜索树的第k个结点

http://www.nowcoder.com/practice/ef068f602dde4d28aab2b210e859150a

题解:二叉树的中序遍历

public class Solution {
    TreeNode res = null; 
    int count=0;
    TreeNode KthNode(TreeNode pRoot, int k) {
        if(pRoot==null||k==0) return null;
        helper(pRoot,k);
        return res;
    }
    
    void helper(TreeNode pRoot,int k){
        if(pRoot==null) return;
        
        helper(pRoot.left,k);
        count++;
        if(count==k){
            res = pRoot;
        }
        helper(pRoot.right,k);
        
    }
}
全部评论

相关推荐

优秀的大熊猫在okr...:多益:此贼,必有同谋,按律,该当连坐!
你不能接受的企业文化有哪...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务