• <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
            給出s1和s2兩個字符串,其中的字符一一對應,這樣的一一對應關系符合:

            Reflexivity: 'a' == 'a'.
            Symmetry: 'a' == 'b' implies 'b' == 'a'.
            Transitivity: 'a' == 'b' and 'b' == 'c' implies 'a' == 'c'.

            另給出一個baseStr,輸出與之對等的字符排序最小的字符串
            并查集,將s1和s2對應位置的字符一一并入相同集合,注意在合并時永遠選擇較小的字符作為父節點

             1 #1061
             2 #Runtime: 26 ms (Beats 87.50%)
             3 #Memory: 13.5 MB (Beats 81.25%)
             4 
             5 class UnionFind:
             6     def __init__(self):
             7         self.parent = {}
             8     def find(self, x):
             9         if x not in self.parent:
            10             self.parent[x] = x
            11         i = x
            12         while x != self.parent[x]:
            13             x = self.parent[x]
            14         self.parent[i] = x
            15         return x
            16     def union(self, x, y):
            17         rx = self.find(x)
            18         ry = self.find(y)
            19         if rx > ry:
            20             self.parent[rx] = ry
            21         else:
            22             self.parent[ry] = rx
            23 
            24 class Solution(object):
            25     def smallestEquivalentString(self, s1, s2, baseStr):
            26         """
            27         :type s1: str
            28         :type s2: str
            29         :type baseStr: str
            30         :rtype: str
            31         """
            32         uf = UnionFind()
            33         for i in range(len(s1)):
            34             uf.union(s1[i], s2[i])
            35         ans = []
            36         for c in baseStr:
            37             ans.append(uf.find(c))        
            38         return ''.join(ans)
            亚洲精品乱码久久久久久蜜桃图片 | 人妻无码精品久久亚瑟影视| 久久久久亚洲国产| 久久w5ww成w人免费| 久久午夜福利电影| 久久99国产综合精品女同| 久久九九免费高清视频| 亚洲精品无码久久久久久| 久久久久女人精品毛片| 国内精品久久久久久久coent| 麻豆亚洲AV永久无码精品久久| 中文国产成人精品久久不卡| 久久人爽人人爽人人片AV| 性做久久久久久久久| 97香蕉久久夜色精品国产| 欧美久久一级内射wwwwww.| 九九久久自然熟的香蕉图片| 奇米影视7777久久精品人人爽| 青青草原综合久久大伊人精品| 久久亚洲美女精品国产精品| 一级女性全黄久久生活片免费| 久久强奷乱码老熟女网站| 91精品国产91久久综合| 欧美亚洲色综久久精品国产| 久久久久久久久久久久久久| 久久久久一级精品亚洲国产成人综合AV区 | 青青青国产精品国产精品久久久久| 久久婷婷国产剧情内射白浆| 一本色道久久88精品综合| 无码人妻久久一区二区三区免费丨| 久久婷婷国产综合精品| 香蕉久久夜色精品升级完成| 久久久国产精品福利免费| 99国产精品久久| 99久久国产亚洲综合精品| www.久久99| 99久久香蕉国产线看观香| 久久人爽人人爽人人片AV | 国产亚洲精品美女久久久| 久久99精品国产麻豆蜜芽| 97久久精品国产精品青草|