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

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ส.ค. 2024

ความคิดเห็น • 22

  • @shrirangjoshi6568
    @shrirangjoshi6568 6 หลายเดือนก่อน +1

    No one has solved this in this way.Thank you!!

  • @floatingfortress721
    @floatingfortress721 7 หลายเดือนก่อน +1

    Thanks, you were able to simplify the problem and its solution for me :)

  • @luminraja09
    @luminraja09 3 หลายเดือนก่อน

    I am a fan of BFS. Thanks Man for the solution. :)

  • @unemployedcse3514
    @unemployedcse3514 17 วันที่ผ่านมา

    awesome ❤

  • @kunalkheeva
    @kunalkheeva ปีที่แล้ว

    Thank you for the edge cases.

  • @dineshdsv7815
    @dineshdsv7815 7 หลายเดือนก่อน

    Thanks for the explanation!!

    • @nikoo28
      @nikoo28  7 หลายเดือนก่อน

      Happy to help!

  • @alisheheryar1770
    @alisheheryar1770 5 หลายเดือนก่อน

    Godspeed Nikhil.

  • @subee128
    @subee128 7 หลายเดือนก่อน +1

    Thanks

  • @brentdaniels5462
    @brentdaniels5462 ปีที่แล้ว +1

    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

  • @smitjoshi7202
    @smitjoshi7202 ปีที่แล้ว

    Which one is better? recursive or iterative? Recursive solutions comes naturally to for trees usually.

    • @nikoo28
      @nikoo28  ปีที่แล้ว +1

      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.

  • @mdshafiuddin1234
    @mdshafiuddin1234 11 หลายเดือนก่อน

    sir please make playlist on recursion this concept is root for all advance concept of dsa

    • @nikoo28
      @nikoo28  11 หลายเดือนก่อน +2

      yes, I will add a playlist on recursion.

  • @leetcode650
    @leetcode650 9 หลายเดือนก่อน

    Please do solution in python or make a poll :(

    • @nikoo28
      @nikoo28  8 หลายเดือนก่อน +1

      try to understand the logic rather than concentrating on the language :)

  • @Amed-pf7dp
    @Amed-pf7dp 4 หลายเดือนก่อน

    there is no need for the extra space

    • @nikoo28
      @nikoo28  4 หลายเดือนก่อน

      What solution would you suggest?

    • @Amed-pf7dp
      @Amed-pf7dp 4 หลายเดือนก่อน

      @@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;
      }
      }

  • @philandros3195
    @philandros3195 5 หลายเดือนก่อน

    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  5 หลายเดือนก่อน

      check out my complete playlist on trees, you will have a very good understanding.