| [ Web Proxy ] |
| Viewing: https://raw.githubusercontent.com/Edwardlinge/JavaArithmetic/master/src/LeetCode/LeetCode104.java | [Back] [Original] |
package LeetCode;
public class LeetCode104 {
// 104. Maximum Depth of Binary Tree
// https://leetcode.com/problems/maximum-depth-of-binary-tree/description/
// : O(n), n
// : O(h), h
// Definition for a binary tree node.
public class TreeNode {
int val;
TreeNode left;
TreeNode right;
TreeNode(int x) { val = x; }
}
public int maxDepth(TreeNode root) {
if(root == null)
return 0;
//
return 1 + Math.max(maxDepth(root.left), maxDepth(root.right));
}
}
| Web Proxy Viewer | New URL | Original Page |