Maximum Depth of Binary Tree

来源:互联网 发布:在哪里可以投诉淘宝网 编辑:程序博客网 时间:2024/05/22 11:48
<pre name="code" class="java">/** * Definition for binary tree * public class TreeNode { *     int val; *     TreeNode left; *     TreeNode right; *     TreeNode(int x) { val = x; } * } */public class Solution {    public int maxDepth(TreeNode root) {        return root==null ? 0 : Math.max(1+maxDepth(root.left), 1+maxDepth(root.right));    }}



0 0
原创粉丝点击