Validate Binary Tree Nodes - Leetcode 1361 - Python

Поделиться
HTML-код
  • Опубликовано: 6 ноя 2024

Комментарии • 13

  • @atharvapatil4247
    @atharvapatil4247 Год назад +6

    Was waiting for this solution today

  • @ngneerin
    @ngneerin Год назад

    Same can be done with stack to reduce memory

  • @amoghsv557
    @amoghsv557 Год назад

    Was waiting for this from 6 hours haha

  • @zerocode-v9w
    @zerocode-v9w Год назад

    Thank you brother

  • @ratnadeepsaha7675
    @ratnadeepsaha7675 Год назад

    Thank you for this video

  • @akhilchauhan9417
    @akhilchauhan9417 Год назад +1

    Can you do it with DSU? I am stuck at 42/44.
    Failed Test Case:
    n = 3
    [1, -1, -1]
    [-1, -1, 1]
    I am checking for connected components == 1 plus no cycles. What am I missing??

    • @Kan-JenLiu
      @Kan-JenLiu Год назад +2

      there are 2 root nodes, which is not a valid binary tree (has only 1 root node)

    • @ngneerin
      @ngneerin Год назад

      Length of all unique nodes is 1 which is not equal to n-1. Should do this check right after making a list of unique nodes. And if fails return false even before doing anything else

    • @akhilchauhan9417
      @akhilchauhan9417 Год назад

      got it just made a ChildToPar hasmap for checking that

    • @ngneerin
      @ngneerin Год назад

      @@akhilchauhan9417 use set instead

  • @Romany_M
    @Romany_M Год назад

    how we can improve the space?

  • @SohilGrandhi
    @SohilGrandhi Год назад

    Thankyou❤

  • @prasadm3614
    @prasadm3614 Год назад

    Love