Stop being the product.
Become the owner.
or
sign uplog in

Recursion is hard for me to wrap my brain around function…

Recursion is hard for me to wrap my brain around

function maxDepth(root: TreeNode | null): number {
if(root == null) {
return 0;
}


let leftDepth = maxDepth(root.left)
let rightDepth = maxDepth(root.right)

return 1 + Math.max(leftDepth, rightDepth)
};

I made this super simple program for leetcode 104, but I have a really hard time in the "think how a program can do what i want phase" to think about a function calling itself I understand it from a top down view

basically just cloning and nesting the function in itself, but its really hard to think about,

when i started this I was thinking how do i write a program that can search in 1 direction count to the end and then start over. which ended up not working.
#technology #dev #programming
source
earnings
2,000 mlx total
$0  total
engagement
2 views
0 reactions

0 comments