If you're looking for today's daily LC (Can Place Flowers) -> kzbin.info/www/bejne/kHjboqSgoc-ji6s
@victoriatfarrell Жыл бұрын
For me I think I prefer to append right and left to the stack and just loop while the stack is non-empty, starting by placing the root in the stack before the while loop. Makes it a very clean solution.
@hyperboliq7 ай бұрын
I was wondering why he didn't do it that way. It was cool to learn another way though.
@RakimMiddya5 ай бұрын
How does this work?
@akhileshgotmare98124 ай бұрын
@@RakimMiddya here is the code I think @victoriatfarrell is referring to def preorderTraversal(self, root: Optional[TreeNode]) -> List[int]: if not root: return [] result = [] stack = [root] while stack: cur = stack.pop() result.append(cur.val) # Append right first, so that left is processed first if cur.right: stack.append(cur.right) if cur.left: stack.append(cur.left) return result
@aadill773 ай бұрын
Exactly I did the same.
@cyclone760 Жыл бұрын
I have never thought of the call stack in this way before... great video
@saraahmed4087 ай бұрын
Thank you so much for the explanation. But why the time complexity will be O(log n) if the tree was a balanced binary tree?
@ashok20896 ай бұрын
It's not the Time Complexity, It's the space complexity he mentioned. So TC is O(n) as we must visit each node. SC is O(h), h is the height of the binary tree, and in the worst case SC could be O(n), in the case of a skewed binary tree. for balanced binary tree SC: O(log n).
@theboss-zk4wx Жыл бұрын
thank you!
@gsivanithin Жыл бұрын
Great explanation! nice
@alexandersmirnov4274 Жыл бұрын
hi Why did you decide to open a new channel? Where should we expect new videos?
@gsivanithin Жыл бұрын
Easy to understand
@chandankhuntia7017 Жыл бұрын
💞
@AbhishekAbhishek-dk2pi4 ай бұрын
Its getting errors 🤦
@wavecheeez12468 күн бұрын
Im really tired of hearing from differen youtubers "its really easy". Its offensive to heare such. Even if its really easy and i know it im here not to take strike in to my dignity, people looking for a help and explenation but not to be frustrated
@wavecheeez12468 күн бұрын
And actually it not even close to easy to understand this... so its kind of mocking when saying "its easy"