Minimum Depth of Binary Tree LeetCode solution in JavaScript

1
var minDepth = function (root) {
2
if (!root) {
3
return 0;
4
}
5
if (root.left && root.right) {
6
return Math.min(minDepth(root.left), minDepth(root.right)) + 1;
7
}
8
if (root.right) {
9
return minDepth(root.right) + 1;
10
}
11
if (root.left) {
12
return minDepth(root.left) + 1;
13
}
14
return 1;
15
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0