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

二叉搜索树的第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);
        
    }
}
全部评论

相关推荐

03-04 17:07
南昌大学 Java
点赞 评论 收藏
分享
03-03 19:02
已编辑
东华理工大学 Node.js
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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