• <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)
            久久五月精品中文字幕| 久久精品人妻一区二区三区| 久久久久久久综合日本| 99蜜桃臀久久久欧美精品网站| 久久经典免费视频| 久久天天躁狠狠躁夜夜avapp| 亚洲国产精品婷婷久久| 色综合久久久久无码专区| 人人狠狠综合久久亚洲| 久久99精品久久只有精品| 久久婷婷五月综合国产尤物app| 香蕉久久影院| 亚洲伊人久久成综合人影院| 久久国产高清一区二区三区| 91精品国产高清久久久久久91| 久久偷看各类wc女厕嘘嘘| 无码伊人66久久大杳蕉网站谷歌| 麻豆久久| 久久一日本道色综合久久| 亚洲国产精品久久电影欧美| 97久久国产综合精品女不卡| 国产香蕉久久精品综合网| 日日噜噜夜夜狠狠久久丁香五月| 久久久久亚洲AV无码专区首JN| 久久亚洲AV成人无码电影| 看全色黄大色大片免费久久久| 久久久久久人妻无码| 狠狠久久综合| 久久精品国产久精国产| 亚洲性久久久影院| 久久久黄片| 久久电影网| 欧美日韩精品久久久久| 久久国产精品国产自线拍免费| 国产精品99久久久久久宅男小说 | 国产精品伊人久久伊人电影 | 色婷婷综合久久久中文字幕| 亚洲国产精品久久久久网站| 久久久无码一区二区三区| 久久伊人五月丁香狠狠色| 久久国产欧美日韩精品免费|