Thanks for explaining this so well. I feel like a lot of coding youtubers don't break down a problem into it's visual side which is so important for learning how something works!
hey, thanks for the great explanation and effort Fisher. I hope you could possibly show a visual explanation for the iterative step as well for those who are not familiar with the LinkedList data structure. Thank you!
Hey, I'm having trouble I wrote the following code but not sure why it returns the wrong answer public int maxDepth(TreeNode root) { if(root==null) return 0;
int maxDepth(TreeNode* root) { int maxDepth = 0; // Initialize the maximum depth int count = 0; // Initialize the current depth counter dfs(root, count, maxDepth); return maxDepth; } private: void dfs(TreeNode* node, int count, int &maxDepth) { if (node == NULL) return; count++; // Increment counter to reflect current depth if (count > maxDepth) { maxDepth = count; // Update maximum depth } dfs(node->left, count, maxDepth); dfs(node->right, count, maxDepth); } }; brother this code works but i cant understand how every recursion call maintain its own count variable
Actually this is the best explanation you can find on youtube....Others just focused on writing the code.Thanks man!
Glad it helped!
Thanks for explaining this so well. I feel like a lot of coding youtubers don't break down a problem into it's visual side which is so important for learning how something works!
Best visualization out there. Thanks
This was the best explanation I could find of this problem, I appreciate you drawing out the recursive calls.
You're very welcome!
best video so far
Thank you, I was looking for exactly this type of diagrammatic explanation! Thank you so much!!!
Glad it was helpful!
Excellent explanation. Thank you! Keep up the good work!
Glad it was helpful!
Level up! My algorithmic intelligence has been increased by 3.
That was the best explanation I've ever seen. Thank you very much!
Glad it was helpful!
hey, thanks for the great explanation and effort Fisher. I hope you could possibly show a visual explanation for the iterative step as well for those who are not familiar with the LinkedList data structure. Thank you!
Great suggestion!
Yeah, I came here for the visual explanation for the iterative approach :(
Thanks for such a detailed explanation,quite informative video.Please also explain code using C++.Please
you are amazing man , love your videos
I appreciate that!
I finally understood recursion , thanks buddy
Glad to hear that
that's a great explanation. Thanks !!
Glad it was helpful!
Excellent explanation. Much appreciated!
Glad it was helpful!
Always the best! Thanks man!
Thank you too!
Hey, I'm having trouble
I wrote the following code but not sure why it returns the wrong answer
public int maxDepth(TreeNode root)
{
if(root==null) return 0;
if(root.left!=null) lh = maxDepth(root.left);
if(root.right!=null) rh = maxDepth(root.right);
return 1+Math.max(lh,rh);
}
public int maxDepth(TreeNode root)
{
if(root==null) return 0;
int lh = maxDepth(root.left);
int rh = maxDepth(root.right);
return 1+Math.max(lh,rh);
}
nice!
pretty good. BTW, I guess you can speak mandarin, right?
int maxDepth(TreeNode* root) {
int maxDepth = 0; // Initialize the maximum depth
int count = 0; // Initialize the current depth counter
dfs(root, count, maxDepth);
return maxDepth;
}
private:
void dfs(TreeNode* node, int count, int &maxDepth) {
if (node == NULL) return;
count++; // Increment counter to reflect current depth
if (count > maxDepth) {
maxDepth = count; // Update maximum depth
}
dfs(node->left, count, maxDepth);
dfs(node->right, count, maxDepth);
}
}; brother this code works but i cant understand how every recursion call maintain its own count variable