632-二叉树遍历

来源:互联网 发布:待遇 知乎 编辑:程序博客网 时间:2024/05/19 08:40
 /*public class TreeNode { *     public int val; *     public TreeNode left, right; *     public TreeNode(int val) { *         this.val = val; *         this.left = this.right = null; */public class Solution {    /**     * @param root the root of binary tree     * @return the max ndoe     */    public TreeNode temp;    public TreeNode maxNode(TreeNode root) {        temp = root;        return Max(root);    }        public TreeNode Max(TreeNode T){        if(T == null)            return T;        if(T.val >= temp.val){            temp = T;        }        Max(T.left);        Max(T.right);        return temp;    }}

20107.3.17 开始刷第一道题,自己真的很渣,慢慢来吧。

二叉树中求值最大的节点,其实也就是遍历一遍就好,用递归就好

但就是迷迷糊糊的弄不清楚

很受打击

多试试就好了。

                                             
0 0