package com.leetcode.problem;
/**
* @author Pxu
* @create 2020-04-21 22:24
*/
public class Problem111 {
public static void main(String[] args) {
}
public int minDepth(TreeNode root) {
if(root == null)
return 0;
else if(root.right == null && root.left == null)
return 1;
else {
int leftDepth = Integer.MAX_VALUE;
int rightDepth = Integer.MAX_VALUE;
if (root.left != null)
leftDepth = minDepth(root.left) + 1;
if (root.right != null)
rightDepth = minDepth(root.right) + 1;
return Integer.min(leftDepth, rightDepth);
}
}
class TreeNode {
int val;
TreeNode left;
TreeNode right;
TreeNode(int x) { val = x; }
}
}