Binary Tree Zigzag Level Order Traversal
it is truly a good way to solve this problem
@anton15 This is actually strange, why do you think that is?
Java version, 2ms:
Here is my Java Double Stack solution:
Using one stack and avoiding creating new list speeds up the code a lot! The flag is brilliant too!!
Steps for solution:
Create an empty stack s and push root to it.
while stack is not NULL Do following:-
Create a empty stack called tempStack.
Pop a node from stack and push it to tempStack depending on directionFlag.
Change directionFlag to change the direction of traversal.
No one has replied
yes. reverse the vector element of odd index
@tlhuang said in 8-liner Python:
Move empty case to while:
I like this deque solution. although it may not be what they want. And there some extra cost of reversing. However, it is indeed much clear and concise.
The reversal part will cause double time-overhead. Even your algorithm is also O(n), the time needed to perform traversal is twice as two-stack version.
Disabled Categories are greyed out
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.