Skip to content

Latest commit

 

History

History
49 lines (33 loc) · 1.15 KB

_1657. Determine if Two Strings Are Close.md

File metadata and controls

49 lines (33 loc) · 1.15 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


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

Solutions

Python

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