That clap at the beginning makes me alert and my mind says please be concentrate you gonna be learn something new
@osxs333__74 жыл бұрын
makes me feel like a dog when you put it like that
@mudassirshahzadkk4 жыл бұрын
You can use recursion for this. It's much easier. Your call stack may increase but it's still gonna be O(n) for both time and space.
@CoolnesXcore4 жыл бұрын
True but the question asks you to do it iteratively.
@mudassirshahzadkk4 жыл бұрын
@@CoolnesXcore You're right. In an interview, you could explain that recursive solution maybe better because this is exactly what they look for. You ability to choose a better solution.
@amanmalhotra20263 жыл бұрын
class Solution { List list = new ArrayList(); public List inorderTraversal(TreeNode root) { if(root == null){ return list; } inorderTraversal(root.left); list.add(root.val); inorderTraversal(root.right); return list; } }
@RishabhMishra-uw9yb3 жыл бұрын
amazing man thanks for the code i was looking for this kind of code
@TheOkayUek3 жыл бұрын
They asked without recursion
@harshsinha32212 жыл бұрын
Everyone is gangsta, until you have to traverse a binary tree iteratively.
@harshitsaxena30643 жыл бұрын
Great Work Nick ! Whenever I saw that you have made a video on any leetcode question I become very happy because I know I will connect with your logic and your thought process.
@mostinho72 жыл бұрын
TODO: take note of this, doing inorder traversal without using recursion
@evanpoole7829 Жыл бұрын
around 0:27 is a great explanation!!
@samyakjain68553 жыл бұрын
Coming back after a year, still impressed...keep up the brilliant work Nick!
@giorgi234 жыл бұрын
Nick you explain well, your implementations are brilliant. don't torture yourself!!! The only thing you need is a white board stuff(maybe e-version) to show more details. Especially for beginners it's sometimes hard to read only from code.
@ericytff738810 ай бұрын
its been 6 years, too good !
@mohammedghabyen7212 жыл бұрын
public class Solution { public IList InorderTraversal(TreeNode root) { IList res = new List(); addData(root,res); return res; } private void addData(TreeNode node,IList res){ if(node==null) return; addData(node.left,res); res.Add(node.val); addData(node.right,res); } }
@paulsnehasish58303 жыл бұрын
so it was medium problem way back in 2018 and now its under easy category :D
@Gideon_Judges65 жыл бұрын
I wonder if the recursive version would give you a better performance rating in java bytecode.
@sannge26314 жыл бұрын
the question asks you to solve the problem iteratively.
@andreykovalov4382 жыл бұрын
i call it "thanks for nothing explanation"
@mohamedsalman69343 жыл бұрын
what is the use of storing the root to current? why cannot we use the root for traversing through the tree?
@user-18873ty3 жыл бұрын
I just have one question, should the one be smart so he can solve those problems? how can I solve new problems by myself if every problem has a new idea
@_abhishekmj_3 жыл бұрын
I m not expert, but I can say it's like solving math problems.. So, you learn few patterns and then apply them for the problems to solve them.. Some will be tough like dynamic programming.. So, need to spend time in learning and keep solving!
@_abhishekmj_3 жыл бұрын
Once you keep doing, you get used to - all skills look difficult before learning!
@hanscesa56783 жыл бұрын
at 6:47 I died hahahaha the explanation is confusing if u're hearing it for the first time, but hearing it again will eventually make sense xD
@sproutboot2 жыл бұрын
2022, now this problem is moved to 'easy'..?
@curtism73024 жыл бұрын
This is from about a year and half ago. Nick, my main man, I bet you could redo this video with a cleaner and little clearer explanation by now. That being said, I did understand after watching this a few times. Also(if you even read these) , Did you get the job at Amazon?
@michaelyao93892 жыл бұрын
Do we need Morris way?
@henry61652 жыл бұрын
Can someone explain why time complexity is o(n) even if we are using two iterations?
@marcoscarlomagno30652 жыл бұрын
Because the complexity does not necessarily depend on the amount of loops, it depends on the time it takes the program to return the result as the input increases, when you add 1 new node to the input the program just requires a new cicle in the big loop. This is linear complexity O(n) = m (array size n, m cicles) O(n+1) = m + 1. (array size n+1, m+1 cicles) O(n+2) = m + 2. (array size n+2, m+2 cicles) As you can see the time increases in a linear relationship with the input.
@abhinavdadhich23114 жыл бұрын
i cant understand plz help..how it going to root first instead of right node after executing 22 line.
@frogery4 жыл бұрын
because you pushed all the left nodes on the stack first -> [1,2,4] so when you pop 4 and go to the next iteration, the root node (2) will be at the top of the stack and get popped, and then 2's right node is added to the stack.
@dengzhonghan51254 жыл бұрын
I had the same questions after watching this video. I just work it out. I hope my explanation would help. When we reach the very left which is 4, then curr = 4 which is the very top of the stack. After that, we save 4 to res. And then, curr.right which is 4's right is None. We will go to the next iteration. Because curr is None, we will not go into the second while loop. The next element in the stack will pop out which is 2. We save 2 to res. Then we set curr = 2's right which is 5. This time curr is not None, we will go into the second while loop so we save 5 in stack.
@sofiayz74724 жыл бұрын
@@dengzhonghan5125 So when the current value is 5, current.left is null and that's why 5 get popped out?
@harshitsaxena30643 жыл бұрын
@@dengzhonghan5125 Thankyou very much deng Your explanation is really good and thanks for clearing my doubt.
@lifeofme31724 жыл бұрын
Thanks but needed a bit clearer explanation.
@benvan37212 жыл бұрын
Thank you. but reading the code is not what I expect. you're having hard time to explain what the code does.
@mrproteinz5 жыл бұрын
why not apply a recursion? Is this more efficient?
@vishalscit5 жыл бұрын
Godfred Oppong the follow up in the problem asks to do it iteratively.
@harshsinha32212 жыл бұрын
Recursion, can eventually lead to stack over low error
@nehurane3 жыл бұрын
Nick great stuff you doing. Explanation does make sense but yeah don’t be nervous as it overwhelms. But keep doing leetcode series
@intermezzoprincess5575 Жыл бұрын
Interestingly, this problem is categorized as "easy" on Leetcode now haha.
@jetdan521 Жыл бұрын
It's helpful and thanks .
@robinmahato5 жыл бұрын
nice explanations
@learning2cube7594 жыл бұрын
It was good man
@abhinavghosh7254 жыл бұрын
i like how he says hopefully it will work when the submission page literally shows he submitted it moments ago also!
@RyeCA3 жыл бұрын
thx man, this helped!
@chenchangyuan65514 жыл бұрын
Thanks
@mdraihatuljannatsaimon5203 жыл бұрын
Can anyone show me how to implement test cases with main method? I feel ashamed that I can't figure it out smh
@andy0401ify2 жыл бұрын
lol. sooooo cute
@pete12882 жыл бұрын
This is all over the place, don't seem to have a grasp on it.