Skip to content

Instantly share code, notes, and snippets.

@cixuuz
Created August 23, 2017 22:31
Show Gist options
  • Select an option

  • Save cixuuz/922711cdaab7615d8c0d9f47b4bac4f8 to your computer and use it in GitHub Desktop.

Select an option

Save cixuuz/922711cdaab7615d8c0d9f47b4bac4f8 to your computer and use it in GitHub Desktop.
[111. Minimum Depth of Binary Tree] #leetcode
class Solution {
// O(n) O(n/h)
public int minDepth(TreeNode root) {
if (root == null) return 0;
int left = minDepth(root.left);
int right = minDepth(root.right);
return (left == 0 || right == 0) ? left + right + 1: Math.min(left, right) + 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment