• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Uriel's Corner

            Research Associate @ Harvard University / Research Interests: Computer Vision, Biomedical Image Analysis, Machine Learning
            posts - 0, comments - 50, trackbacks - 0, articles - 594
            給出一個字符串集合,其中每個字符串都由相同的字母組合通過不同排列構成,如果兩個字符串可以通過交換兩個字符變成相同字符串,則二者分為同一組,問所有字符串可以分成幾組,并查集
            這題加不加路徑優化速度差不多


             1 #839
             2 #Runtime: 341 ms (Beats 65.91%)
             3 #Memory: 13.9 MB (Beats 79.55%)
             4 
             5 class Solution(object):
             6     def numSimilarGroups(self, strs):
             7         """
             8         :type strs: List[str]
             9         :rtype: int
            10         """
            11         fa = [i for i in range(len(strs))]
            12         #rank = [0] * len(strs)
            13         def find(x):
            14             i = x
            15             while x != fa[x]:
            16                 x = fa[x]
            17             fa[i] = x
            18             return x
            19 
            20         def union(a, b):
            21             fa[find(a)] = find(b)
            22 
            23         def is_similar(x, y):
            24             tp = 0
            25             for i in range(len(x)):
            26                 if x[i] != y[i]:
            27                     tp += 1
            28                     if tp > 2:
            29                         return False
            30             return True
            31         
            32         n_group = len(strs)
            33         for i in range(len(strs)):
            34             for j in range(i + 1, len(strs)):
            35                 if find(i) != find(j) and is_similar(strs[i], strs[j]):
            36                     n_group -= 1
            37                     union(i, j)
            38         return n_group
            久久免费高清视频| 国产精品99久久99久久久| 国产女人aaa级久久久级| 亚洲а∨天堂久久精品9966| 亚洲国产成人久久一区WWW| 久久久SS麻豆欧美国产日韩| 亚洲va久久久噜噜噜久久男同| 久久精品视屏| 久久亚洲精品成人AV| 午夜精品久久影院蜜桃| 色综合久久中文字幕无码| 香蕉久久一区二区不卡无毒影院 | 青青草国产精品久久久久| 国产精品一区二区久久精品无码 | 思思久久精品在热线热| 久久精品国产亚洲网站| 久久精品国产亚洲AV香蕉| 国内精品久久九九国产精品| 无码国内精品久久综合88| 93精91精品国产综合久久香蕉| 亚洲精品无码久久千人斩| 亚洲欧美成人久久综合中文网 | 久久人人超碰精品CAOPOREN| www性久久久com| 久久婷婷五月综合色高清| 亚洲欧美成人久久综合中文网 | 狠狠色婷婷综合天天久久丁香 | 免费精品国产日韩热久久| 久久成人18免费网站| 久久被窝电影亚洲爽爽爽| 久久婷婷五月综合色奶水99啪| 久久综合狠狠综合久久97色| 伊人久久大香线蕉精品| 99久久国产综合精品麻豆| 99久久精品国产免看国产一区| 久久伊人精品一区二区三区 | 久久亚洲精品无码aⅴ大香| 婷婷久久综合九色综合绿巨人| 大美女久久久久久j久久| 久久成人精品| 久久久久亚洲av综合波多野结衣|