LeetCode 104. Maximum Depth of Binary Tree java soluiton

来源:互联网 发布:baocms9完整源码 编辑:程序博客网 时间:2024/05/29 13:51

题目要求:
寻找二叉树的最大树深

/** * Definition for a binary tree node. * public class TreeNode { *     int val; *     TreeNode left; *     TreeNode right; *     TreeNode(int x) { val = x; } * } */public class Solution {    public int maxDepth(TreeNode root) {        if (root == null) {            return 0;        }        int left = maxDepth(root.left);        int right = maxDepth(root.right);        return Math.max(left, right) + 1;    }}
0 0
原创粉丝点击