Created
August 23, 2017 22:31
-
-
Save cixuuz/922711cdaab7615d8c0d9f47b4bac4f8 to your computer and use it in GitHub Desktop.
[111. Minimum Depth of Binary Tree] #leetcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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