Тёмный

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

Nikhil Lohia
Подписаться 49 тыс.
Просмотров 7 тыс.
50% 1

Опубликовано:

 

1 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 24   
@AniketWaghmare-qi7wm
@AniketWaghmare-qi7wm Месяц назад
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 9 месяцев назад
Thanks, you were able to simplify the problem and its solution for me :)
@philandros3195
@philandros3195 7 месяцев назад
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 6 месяцев назад
check out my complete playlist on trees, you will have a very good understanding.
@unemployedcse3514
@unemployedcse3514 Месяц назад
awesome ❤
@shrirangjoshi6568
@shrirangjoshi6568 7 месяцев назад
No one has solved this in this way.Thank you!!
@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
@luminraja09
@luminraja09 5 месяцев назад
I am a fan of BFS. Thanks Man for the solution. :)
@subee128
@subee128 9 месяцев назад
Thanks
@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.
@kunalkheeva
@kunalkheeva Год назад
Thank you for the edge cases.
@alisheheryar1770
@alisheheryar1770 6 месяцев назад
Godspeed Nikhil.
@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.
@Amed-pf7dp
@Amed-pf7dp 6 месяцев назад
there is no need for the extra space
@nikoo28
@nikoo28 5 месяцев назад
What solution would you suggest?
@Amed-pf7dp
@Amed-pf7dp 5 месяцев назад
@@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 19 дней назад
@@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
@leetcode650
@leetcode650 10 месяцев назад
Please do solution in python or make a poll :(
@nikoo28
@nikoo28 9 месяцев назад
try to understand the logic rather than concentrating on the language :)
@dineshdsv7815
@dineshdsv7815 9 месяцев назад
Thanks for the explanation!!
@nikoo28
@nikoo28 8 месяцев назад
Happy to help!
Далее
Шоколадная девочка
00:23
Просмотров 730 тыс.
Шоколадная девочка
00:23
Просмотров 730 тыс.