Leetcode Algorithms-104.Maximum Depth of Binary Tree

问题地址

Maximum Depth of Binary Tree - LeetCode

问题描述

0.jpg

解法

1
2
3
4
5
6
7
8
9
10
11
12
13
public class Solution {

public int maxDepth(TreeNode root) {
return null == root ? 0 : Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
}
}

class TreeNode {
int val;
TreeNode left;
TreeNode right;
TreeNode(int x) { val = x; }
}
0%