That clap at the beginning makes me alert and my mind says please be concentrate you gonna be learn something new
@osxs333__7
4 жыл бұрын
makes me feel like a dog when you put it like that
@ConwellConwell
11 ай бұрын
Nick helped code 911 and grinder
@sproutboot
2 жыл бұрын
2022, now this problem is moved to 'easy'..?
@amanmalhotra2026
3 жыл бұрын
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-uw9yb
3 жыл бұрын
amazing man thanks for the code i was looking for this kind of code
@TheOkayUek
3 жыл бұрын
They asked without recursion
@harshsinha3221
2 жыл бұрын
Everyone is gangsta, until you have to traverse a binary tree iteratively.
@harshitsaxena3064
3 жыл бұрын
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.
@giorgi23
4 жыл бұрын
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.
@samyakjain6855
3 жыл бұрын
Coming back after a year, still impressed...keep up the brilliant work Nick!
@mostinho7
Жыл бұрын
TODO: take note of this, doing inorder traversal without using recursion
@mudassirshahzadkk
4 жыл бұрын
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.
@CoolnesXcore
4 жыл бұрын
True but the question asks you to do it iteratively.
@mudassirshahzadkk
4 жыл бұрын
@@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.
@Gideon_Judges6
4 жыл бұрын
I wonder if the recursive version would give you a better performance rating in java bytecode.
@sannge2631
4 жыл бұрын
the question asks you to solve the problem iteratively.
@omarsh5269
3 жыл бұрын
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!
@paulsnehasish5830
2 жыл бұрын
so it was medium problem way back in 2018 and now its under easy category :D
@mohamedsalman6934
3 жыл бұрын
what is the use of storing the root to current? why cannot we use the root for traversing through the tree?
@evanpoole7829
9 ай бұрын
around 0:27 is a great explanation!!
@mohammedghabyen721
2 жыл бұрын
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); } }
@hanscesa5678
2 жыл бұрын
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
@curtism7302
4 жыл бұрын
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?
@ericytff7388
7 ай бұрын
its been 6 years, too good !
@michaelyao9389
2 жыл бұрын
Do we need Morris way?
@henry6165
2 жыл бұрын
Can someone explain why time complexity is o(n) even if we are using two iterations?
@marcoscarlomagno3065
Жыл бұрын
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.
@abhinavdadhich2311
4 жыл бұрын
i cant understand plz help..how it going to root first instead of right node after executing 22 line.
@frogery
4 жыл бұрын
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.
@dengzhonghan5125
4 жыл бұрын
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.
@sofiayz7472
3 жыл бұрын
@@dengzhonghan5125 So when the current value is 5, current.left is null and that's why 5 get popped out?
@harshitsaxena3064
3 жыл бұрын
@@dengzhonghan5125 Thankyou very much deng Your explanation is really good and thanks for clearing my doubt.
@andreykovalov438
2 жыл бұрын
i call it "thanks for nothing explanation"
@jetdan521
11 ай бұрын
It's helpful and thanks .
@nehurane
3 жыл бұрын
Nick great stuff you doing. Explanation does make sense but yeah don’t be nervous as it overwhelms. But keep doing leetcode series
@learning2cube759
4 жыл бұрын
It was good man
@lifeofme3172
4 жыл бұрын
Thanks but needed a bit clearer explanation.
@benvan3721
Жыл бұрын
Thank you. but reading the code is not what I expect. you're having hard time to explain what the code does.
@mrproteinz
4 жыл бұрын
why not apply a recursion? Is this more efficient?
@vishalscit
4 жыл бұрын
Godfred Oppong the follow up in the problem asks to do it iteratively.
@harshsinha3221
2 жыл бұрын
Recursion, can eventually lead to stack over low error
@robinmahato
5 жыл бұрын
nice explanations
@RyeCA
3 жыл бұрын
thx man, this helped!
@chenchangyuan6551
4 жыл бұрын
Thanks
@intermezzoprincess5575
Жыл бұрын
Interestingly, this problem is categorized as "easy" on Leetcode now haha.
@mdraihatuljannatsaimon520
3 жыл бұрын
Can anyone show me how to implement test cases with main method? I feel ashamed that I can't figure it out smh
@andy0401ify
2 жыл бұрын
lol. sooooo cute
@abhinavghosh725
4 жыл бұрын
i like how he says hopefully it will work when the submission page literally shows he submitted it moments ago also!
@pete1288
2 жыл бұрын
This is all over the place, don't seem to have a grasp on it.
Пікірлер: 53