Same Tree (LeetCode 100) | Full solution with visuals and animations | Study Algorithms

  Рет қаралды 7,181

Nikhil Lohia

Nikhil Lohia

Күн бұрын

Пікірлер: 24
@shrirangjoshi6568
@shrirangjoshi6568 9 ай бұрын
No one has solved this in this way.Thank you!!
@AniketWaghmare-qi7wm
@AniketWaghmare-qi7wm 2 ай бұрын
Bro please make video on Question Number 110. Balanced Binary Tree.and your Teaching technique is so good. Please make video urjently because my Amazon interview schedule in next week
@floatingfortress721
@floatingfortress721 10 ай бұрын
Thanks, you were able to simplify the problem and its solution for me :)
@alisheheryar1770
@alisheheryar1770 8 ай бұрын
Godspeed Nikhil.
@luminraja09
@luminraja09 6 ай бұрын
I am a fan of BFS. Thanks Man for the solution. :)
@kunalkheeva
@kunalkheeva Жыл бұрын
Thank you for the edge cases.
@brentdaniels5462
@brentdaniels5462 Жыл бұрын
Can you do a tutorial on the recusive solution? figiured out the itreative solution but I am still a little bit confused on how the recusive solution works.
@nikoo28
@nikoo28 Жыл бұрын
if you understand the iterative solution, that is all you need. A recursive solution if often confusing. If you still want a recursive solution, you might find one in the leetcode discuss section. I would not recommend it though
@LOUD_Ruffian
@LOUD_Ruffian Жыл бұрын
Which one is better? recursive or iterative? Recursive solutions comes naturally to for trees usually.
@nikoo28
@nikoo28 Жыл бұрын
i usually prefer an iterative approach, as it is more easy to debug. Think about a scenario when you are trying to understand the flow and find what is going wrong. With a recursive approach, you will get stuck in cycles, and it gets very hard. At the end it comes down to preference.
@dineshdsv7815
@dineshdsv7815 10 ай бұрын
Thanks for the explanation!!
@nikoo28
@nikoo28 10 ай бұрын
Happy to help!
@subee128
@subee128 10 ай бұрын
Thanks
@unemployedcse3514
@unemployedcse3514 3 ай бұрын
awesome ❤
@mdshafiuddin1234
@mdshafiuddin1234 Жыл бұрын
sir please make playlist on recursion this concept is root for all advance concept of dsa
@nikoo28
@nikoo28 Жыл бұрын
yes, I will add a playlist on recursion.
@leetcode650
@leetcode650 Жыл бұрын
Please do solution in python or make a poll :(
@nikoo28
@nikoo28 11 ай бұрын
try to understand the logic rather than concentrating on the language :)
@Amed-pf7dp
@Amed-pf7dp 8 ай бұрын
there is no need for the extra space
@nikoo28
@nikoo28 7 ай бұрын
What solution would you suggest?
@Amed-pf7dp
@Amed-pf7dp 7 ай бұрын
@@nikoo28 class Solution { public boolean isSameTree(TreeNode p, TreeNode q) { if (p == null && q == null) { return true; } if (p != null && q != null && p.val == q.val) { return isSameTree(p.left, q.left) && isSameTree(p.right, q.right); } return false; } }
@intellectualgamers8623
@intellectualgamers8623 2 ай бұрын
@@Amed-pf7dp The space complexity of this solution is O(n) in the worst case, as the recursive calls will use space on the call stack proportional to the height of the tree
@philandros3195
@philandros3195 9 ай бұрын
I don't think I understand how the tree works. In the first test case the trees are q = [1, 2, 3] and p = [1, 2, 3] and if I write: return q.val == p.val and q.left == p.left and q.right == p.right, the output is False??? Also if I try just return q (for science), I would expect the output to be the tree [1,2,3], but instead the output is True?? What the fuck. How do these damn trees work?!?
@nikoo28
@nikoo28 8 ай бұрын
check out my complete playlist on trees, you will have a very good understanding.
小路飞还不知道他把路飞给擦没有了 #路飞#海贼王
00:32
路飞与唐舞桐
Рет қаралды 87 МЛН
8 patterns to solve 80% Leetcode problems
7:30
Sahil & Sarra
Рет қаралды 438 М.