Leetcode - Determine if Two Strings Are Close (Python)

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

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

  • @muzaffartursunov324
    @muzaffartursunov324 10 месяцев назад +1

    How do you come up with such a great ideas?! I appreciate it! Thank you Tim!

  • @TimBrownYoutube
    @TimBrownYoutube 6 месяцев назад

    Wanted to share refactored version:
    def closeStrings(self, word1: str, word2: str) -> bool:
    hist1 = Counter(word1)
    hist2 = Counter(word2)
    hist3 = Counter(hist1.values())
    hist4 = Counter(hist2.values())
    return hist3 == hist4 and set(word1) == set(word2)

  • @Alpha16212
    @Alpha16212 10 месяцев назад +1

    great explanation! thanks a lot for this!

  • @patrikm8389
    @patrikm8389 9 месяцев назад

    I think you can remove the c1==c2 condition as it should already be included in the second condition. if c1 equals c2 means that both strings share the same set of chars and the same distribution of counts
    Thanks a lot for the videos, watched a couple and they were short but very clear and easy to understand

    • @onetwothree164
      @onetwothree164 9 месяцев назад

      was thinking the same thing as well :)

  • @waleeddib7096
    @waleeddib7096 3 года назад +1

    The first thing that comes to your mind is recursion. Every single time lol

    • @timc3406
      @timc3406  3 года назад

      Tell me about it!

  • @sanooosai
    @sanooosai Месяц назад

    thank you sir

  • @bricksnbuttons2000
    @bricksnbuttons2000 9 месяцев назад

    Great explanation! Thanks!

  • @liliiarudenko
    @liliiarudenko 9 месяцев назад

    great video 😎

  • @chickaberga2
    @chickaberga2 3 года назад

    Why did you do a list comprehension [v for v in c1.values()]? Is this not just the same as simply c1.values()?

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

    damn it sefficent as fuck