LeetCode solutions

2594. Count Pairs Of Similar Strings

My accepted Python solution to LeetCode problem 2594, Count Pairs Of Similar Strings, running in 24ms.

  • Difficulty: Easy
  • Python
  • Runtime 24ms
  • Memory 12.7MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 24ms, memory 12.7MB, accepted 2025-12-24.

python
class Solution(object):
    def similarPairs(self, words):
        from collections import Counter
        signatures = [frozenset(word) for word in words]
        count = 0
        n = len(signatures)
        for i in range(n):
            for j in range(i + 1, n):
                if signatures[i] == signatures[j]:
                    count += 1
        return count

Source