Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9d84e64

Browse files
committed
minimum depth
1 parent 52cd198 commit 9d84e64

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
object Solution {
2+
def minDepth(root: TreeNode): Int = {
3+
if (root == null){
4+
0
5+
}else if (root.left == null && root.right == null){
6+
1
7+
}else if (root.left == null) {
8+
minDepth(root.right) + 1
9+
}else if (root.right == null) {
10+
minDepth(root.left) + 1
11+
}else{
12+
Math.min(minDepth(root.left), minDepth(root.right)) + 1
13+
}
14+
}
15+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /