Maximum Depth of Binary Tree

来源:互联网 发布:财经日历重要数据解读 编辑:程序博客网 时间:2024/05/29 12:40
/** * Definition for a binary tree node. * public class TreeNode { *     int val; *     TreeNode left; *     TreeNode right; *     TreeNode(int x) { val = x; } * } */public class Solution {    int count = 0;    int max = 0;    public int maxDepth(TreeNode root) {        count++;        if(root != null) {            maxDepth(root.left);            count--;            max = Math.max(max,count);            maxDepth(root.right);            count--;            max = Math.max(max,count);        }        return max;    }}

0 0
原创粉丝点击