Problem Minimum Depth of Binary Tree
Problem Description:
Given a binary tree, find its minimum depth.
The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.
Solution:
1 public int minDepth(TreeNode root) { 2 if (root == null) return 0; 3 int left = minDepth(root.left); 4 int right = minDepth(root.right); 5 return 1 + (left == 0 ? right : (right == 0 ? left : Math.min(left, right))); 6 }