LeetCode Binary Tree Inorder Traversal Solution Explained - Java

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


Preparing For Your Coding Interviews? Use These Resources
————————————————————

Other Social Media
----------------------------------------------

Show Support
------------------------------------------------------------------------------

#coding #programming #softwareengineering
Рекомендации по теме
Комментарии
Автор

That clap at the beginning makes me alert and my mind says please be concentrate you gonna be learn something new

sivaganesh
Автор

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.

harshitsaxena
Автор

Coming back after a year, still impressed...keep up the brilliant work Nick!

samyakjain
Автор

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.

giorgi
Автор

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.

mudassirshahzadkk
Автор

class Solution {
List list = new ArrayList<Integer>();
public List<Integer> inorderTraversal(TreeNode root) {
if(root == null){
return list;
}

inorderTraversal(root.left);
list.add(root.val);
inorderTraversal(root.right);

return list;
}
}

amanmalhotra
Автор

TODO: take note of this, doing inorder traversal without using recursion

mostinho
Автор

what is the use of storing the root to current? why cannot we use the root for traversing through the tree?

mohamedsalman
Автор

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

hanscesa
Автор

public class Solution {
public IList<int> InorderTraversal(TreeNode root) {
IList<int> res = new List<int>();
addData(root, res);
return res;
}

private void addData(TreeNode node, IList<int> res){
if(node==null)
return;
addData(node.left, res);
res.Add(node.val);
addData(node.right, res);
}
}

mohammedghabyen
Автор

I wonder if the recursive version would give you a better performance rating in java bytecode.

Gideon_Judges
Автор

so it was medium problem way back in 2018 and now its under easy category :D

paulsnehasish
Автор

i cant understand plz help..how it going to root first instead of right node after executing 22 line.

abhinavdadhich
Автор

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

ty
Автор

Can someone explain why time complexity is o(n) even if we are using two iterations?

henry
Автор

Nick great stuff you doing. Explanation does make sense but yeah don’t be nervous as it overwhelms. But keep doing leetcode series

nehurane
Автор

2022, now this problem is moved to 'easy'..?

sproutboot
Автор

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?

curtism
Автор

i call it "thanks for nothing explanation"

andreykovalov
Автор

why not apply a recursion? Is this more efficient?

mrproteinz