Determine if Two Strings Are Close - Python #leetcode #leetcode75

preview_player
Показать описание
Explaining how to solve Determine if Two Strings Are Close from leetcode in Python!

@1:58 - Example + Explanation
@2:33 & @4:17 - Code
@3:58 - Code Walkthrough with Example
@7:00 - Time and Space Complexity

Music: Bensound

Lemme know if you have any comments or questions!:)))

Socials:

Playlists:

Рекомендации по теме
Комментарии
Автор

The best moment in every video "...And, it is accepted". 😂😂 That satisfaction after seeing Success.

Arjun-du
Автор

Awesome vid but minor note - for those of us not using python (js pleb, ik), it would be super helpful if things like creating a counting dict weren't abstracted away via an import. Just a thought, but either way, grateful for the vid :)

dinglegary
Автор

Thank you for posting a Medium finally

glasskey_
Автор

Why check for the values when you are checking for the length already? The characters can be transformed to other existing characters within the string so it should not matter.

joneskiller
Автор

Small correction: ```return (sorted(counts1.keys()) == sorted(counts2.keys())) and (sorted(counts1.values()) == sorted(counts2.values()))```

shravan
Автор

made it without collections, and dicts, and more readable as well, beats 99.99 %
class Solution:
def closeStrings(self, word1: str, word2: str) -> bool:
word1_vals, word2_vals = set(word1), set(word2)
if (
len(word1) != len(word2)
or word1_vals != word2_vals
):
return False
else:
word1_frequencies: List[int] = sorted(
[word1.count(letter) for letter in word1_vals]
)
word2_frequencies: List[int] = sorted(
[word2.count(letter) for letter in word2_vals]
)

return word1_frequencies == word2_frequencies

jango