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
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 24ms, memory 12.7MB, accepted 2025-12-24.
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