Minimum Depth of Binary Tree | LeetCode 111 | Coding Interview Tutorial
Vložit
- čas přidán 26. 07. 2024
- Minimum Depth of Binary Tree solution: LeetCode 111
Implement a queue in JavaScript: • Implement a Queue Tuto...
Code and written explanation: terriblewhiteboard.com/minimu...
Link to problem: leetcode.com/problems/minimum...
Buy Me a Coffee: www.buymeacoffee.com/terrible...
AFFILIATE LINKS
If you're interested in learning algorithms, these are great resources.
💻 40% off Tech Interview Pro: techinterviewpro.com/terriblew...
⌨️ 20% off CoderPro: coderpro.com/terriblewhiteboard
💲 All coupons and discounts 💲
terriblewhiteboard.com/coupon...
Minimum Depth of Binary Tree | LeetCode 111 | Coding Interview
#minimumdepthofbinarytreeii #leetcode #algorithms #terriblewhiteboard #codinginterview
Click the time stamp to jump to different parts of the video.
00:00 Title
00:06 Problem readout
00:37 Whiteboard solution
06:11 Coding solution
12:16 Result and outro
If there are any videos you'd like me to make or if you have any ideas on how to optimize this solution, let me know!
Could you please explain the time and space complexity?
invert a binary tree! thanks for these :)
so glad I found your channel. And its in Javascript!! thank you
Thanks a lot for such a great explanation. I really like this approach. I was thinking to go for DFS , but BFS seems to win my heart.
You're welcome!
Best BFS explanation so far
Your videos help so much, thanks for making these series
Great solution, thank youyou!. I noticed it shows a runtime of 240ms when I try to run it though, Am I missing something?
// following solution is similar to "Level order travelsal ii"
var minDepth = function(root) {
if(!root) return 0;
if(!root.left && !root.right) return 1;
let q = [root], depth = 0, isFound = false;
while(q.length !== 0 && !isFound){
let nodeCount = q.length;
while(nodeCount !== 0){
const current = q.shift();
if(!current.left && !current.right){
isFound = true;
break;
}
if(current.left) q.push(current.left);
if(current.right) q.push(current.right);
nodeCount--;
}
depth++
}
return depth;
}