Binary Tree Zigzag Level Order Traversal - LeetCode 103 Python

preview_player
Показать описание

Explaining Binary Tree Zigzag Level Order Traversal in Python

Music: Bensound

Lemme know up if y'all have any questions/comments!:)
Рекомендации по теме
Комментарии
Автор

Great vid ! Your explanation was very idiosyncratic and conspicuous.


Just a quick question tho, how do I get to your level ? Your approach to the problem made it seem so easy.
But whenever I look at these sorta questions I sit completely blank with Zilch in my mind.

I have solved approximately 100 questions on LeetCode so far on different topics but still I just can't come up
with a solution right away.


Is there something that you can suggest for a better way of solving problems like these other than brute force ?

abhineetsharma
Автор

Great explanation there Deepti. This is the first video I am watching from you and already a fan. Keep going and please help with any useful links/online content which can help me get better to think through any Algo-DS related questions

pathapac
Автор

Can anyone explain me how this is O(n)..there were two while loops inside a while loop..plz explain

HariHaran-slpg
Автор

really good solution! thank you so much

sagarpotnis
Автор

Thank you very much for the walk throught!!

hildesong
Автор

so when you pop. the type of root should be TreeNode right. But leetcode is saying it is of Type Int

root = s1.pop()
level.append(root.val) ---> Getting error for this saying type int has no attribute val

Mohib
Автор

It's so well explained especially in the last 2 mins. Thank you.

shubhamkurup
Автор

Well explained Plz upload more videos ...🙏🏿

AnshuKumar-znqb
Автор

good !! plz make videos on strings questions

anmolwadali
Автор

Very nice effort. what i think that you can perform this in such a way that apply dfs, if its even level go from left to right and if its even move from right to left. In this way you can optimise your solution.

anasshah
Автор

Good explanation, Deepti. I'm using your videos in tandem with those by Neetcode to brush up on my DS and Algos. I like how you walkthrough the problems using the Leetcode interface. At the moment, I keep tripping up by making silly mistakes with the references or missing out some things even if I know the algorithm.

aaditkamat
Автор

plzz help with the iterative postorder a bit more complex than other 2 traversls....please help with this.

Kushagra_
Автор

This is so cool! but why are we checking if level != []

saibharadwajvedula
Автор

A small trick with Level Order traversal would also work.

class Solution:
def zigzagLevelOrder(self, root: Optional[TreeNode]) -> List[List[int]]:
if not root:
return []

queue = [root]
level = []
result = []
lvl = 0

while queue:
q2 = []
for root in queue:
level.append(root.val)
if root.left:
q2.append(root.left)
if root.right:
q2.append(root.right)

result.append(level if lvl % 2 == 0 else reversed(level))
level = []
queue = q2
lvl += 1

return result

parvathirajan.n
visit shbcf.ru