Leetcode 929 Solution
This article provides solution to leetcode question 929 (groups-of-special-equivalent-strings)
Access this page by simply typing in "lcs 929" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/groups-of-special-equivalent-strings
Solution
class Solution:
def numSpecialEquivGroups(self, A: List[str]) -> int:
m = set()
for word in A:
s1 = []
s2 = []
for i, ch in enumerate(word):
if i % 2 == 0:
s1.append(ch)
else:
s2.append(ch)
s1.sort()
s2.sort()
key = ("".join(s1), "".join(s2))
m.add(key)
return len(m)