Error
|
|
---|---|
@Ibrahim Nash | 5761 |
@blackshadows | 5715 |
@akhayrutdinov | 5111 |
@mb1973 | 4989 |
@Quandray | 4944 |
@saiujwal13083 | 4506 |
@sanjay05 | 3762 |
@marius_valentin_dragoi | 3516 |
@sushant_a | 3459 |
@verma_ji | 3341 |
@KshamaGupta | 3318 |
Complete Leaderboard | |
|
|
@aroranayan999 | 1083 |
@bt8816103042 | 739 |
@SherlockHolmes3 | 444 |
@SHOAIBVIJAPURE | 430 |
@codeantik | 429 |
@shalinibhataniya1097 | 400 |
@ShamaKhan1 | 392 |
@neverevergiveup | 372 |
@amrutakashikar2 | 355 |
@murarry3625 | 350 |
@mahlawatep | 349 |
Complete Leaderboard |
Given a binary tree, find its minimum depth.
Example 1:
Input: 1 / \ 3 2 / 4 Output: 2 Explanation: Minimum depth is between nodes 1 and 2 since minimum depth is defined as the number of nodes along the shortest path from the root node down to the nearest leaf node.
Example 2:
Input: 10 / \ 20 30 \ \ 40 60 / 2 Output: 3 Explanation: Minimum depth is between nodes 10,20 and 40.
Your Task:
You don't need to read input or print anything. Complete the function minDepth() which takes the root node as an input parameter and returns the minimum depth.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(height of the tree)
Constraints:
1 ≤ N ≤ 10^5
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes