All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : July 13, 2024
Last updated : July 13, 2024
Related Topics : Hash Table, String, Sorting, Counting
Acceptance Rate : 54.648 %
Notes
- Operation 1: if is any permutation basically
- Operation 2: if count of frequencies matches ignoring actual letters
class Solution:
def closeStrings(self, word1: str, word2: str) -> bool:
if word1 == word2 :
return True
cnt1, cnt2 = Counter(word1), Counter(word2)
freqCnt1, freqCnt2 = Counter(cnt1.values()), Counter(cnt2.values())
if freqCnt1 == freqCnt2 and cnt1.keys() == cnt2.keys() :
return True
return False