LintCode 二叉树的最大节点

来源:互联网 发布:淘宝店铺banner尺寸 编辑:程序博客网 时间:2024/06/10 18:58
    static int i;    static TreeNode p;   static public TreeNode maxNode(TreeNode root) {        // write your code here       if(root==null)return null;        p=root;        i=root.val;        findmax(root);        return p;    }    static public void findmax(TreeNode root){       if(root!=null){           findmax(root.left);           findmax(root.right);           if(root.val>p.val&&root.val>i)           {               p=root;               i=root.val;           }       }    }
原创粉丝点击