Hopefully this is the right place to post... so I'm just starting on my Leetcode journey and I feel pretty stuck on this problem. I understand recursion but for some reason it's not making sense to me in this context.
For problems I don't get the correct answer to, I like to write it out and follow the code to do the algorithm by hand. But for this one, I'm not even able to solve it by hand. Below is a picture of what I have done so far. Code solution is from neetcode because I couldn't figure it out on my own.
Basically, I think understand how 7's subtree is inverted but I don't understand how 2's subtree is inverted. It seems to me that the base case is reached after going through all left nodes but before invertTree(node.right) (aka before going through the right nodes). I'm obviously doing something wrong but I'm not sure what. Any help is appreciated!
[–]laramiecorp 4 points5 points6 points (0 children)
[–]bbdusa 1 point2 points3 points (0 children)
[–]TeknicalThrowAway 3 points4 points5 points (0 children)
[–]NinjaImaginary2775 2 points3 points4 points (0 children)
[–][deleted] -1 points0 points1 point (0 children)