Leetcode - Determine if Two Strings Are Close (Python)

Sdílet
Vložit
  • čas přidán 21. 01. 2021
  • January 2021 Leetcode Challenge
    Leetcode - Determine if Two Strings Are Close #1657
  • Věda a technologie

Komentáře • 12

  • @muzaffartursunov324
    @muzaffartursunov324 Před 6 měsíci +1

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

  • @Alpha16212
    @Alpha16212 Před 7 měsíci +1

    great explanation! thanks a lot for this!

  • @TimBrownYoutube
    @TimBrownYoutube Před 3 měsíci

    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)

  • @waleeddib7096
    @waleeddib7096 Před 3 lety +1

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

  • @patrikm8389
    @patrikm8389 Před 6 měsíci

    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

  • @liliiarudenko
    @liliiarudenko Před 6 měsíci

    great video 😎

  • @chickaberga2
    @chickaberga2 Před 3 lety

    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 Před 9 měsíci

    damn it sefficent as fuck

  • @bricksnbuttons2000
    @bricksnbuttons2000 Před 6 měsíci

    Great explanation! Thanks!