Master Data Structures & Algorithms For FREE at AlgoMap.io!
@christianjt70184 ай бұрын
Great solution! I suggest a minor optimization: check the subtree only if the node and the head of the subroot have the same value.
@franciscoserra8455Ай бұрын
I tested that out and the difference was minus 4 ms on average, so that's really really really a minor optimization that I would disregard in order to prioritize code readability :)
@JoeTan-nq4fq6 күн бұрын
Can further optimise by using stack (instead of recursion). stack = [root] while stack: node = stack.pop() # Initiate comparison if root nodes are the same if node.val == subRoot.val and isSameTree(node, subRoot): return True # Append child nodes if exist if node.right: stack.append(node.right) if node.left: stack.append(node.left) return False
@LemesaElias3 ай бұрын
I like how you approach problems and how you don't use some weird built-in functions. Everything is clear and understandable.
@updownftw17 күн бұрын
Hi Greg, what App are you using for Drawing ?
@jacky-L-3277 ай бұрын
what’s the m + n solution
@GregHogg7 ай бұрын
You can read about it in the leetcode editorial section, it's kinda weird
@aly74016 ай бұрын
Thank you for your tree-based problems video 🎉
@saideep7510Ай бұрын
@@GregHogg But would this (m*n) solution be good enough for faang interview or would we be expected to know (m+n) solution as well?
@youngbaron1504Ай бұрын
@@saideep7510i think m+n is very advanced
@piglovesasy3 ай бұрын
this does not feel like an easy problem, more like a medium
@praneetkomandur65765 ай бұрын
do we need to really know about the time complexity of every leetcode problem we solve