1
# Runtime: 5068 ms (Top 15.23%) | Memory: 14.3 MB (Top 64.62%)2
class Solution: # 839. Similar String Groups3
def numSimilarGroups(self, strs: List[str]) -> int:7
for i in range(len(strs)):10
self.dfs(strs, i, visited)11
# add a new connected area15
# dfs to search the similar string from 0 to n-116
def dfs(self, strs, i, visited):17
# add current string to memo19
for j in range(len(strs)):20
if self.isSimilar(strs[i], strs[j]) and j not in visited:21
self.dfs(strs, j, visited)23
# calculate the similarity of two strings24
def isSimilar(self, str1, str2):26
for i in range(len(str1)):27
if str1[i] != str2[i]:29
return diff_count <= 2