• <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
            復(fù)雜度O(mn)不曉得能不能貓過,直接想了O(m+n)的
            先用字典預(yù)處理,判斷s是否一定包含t,是的話維護(hù)兩個指針pos_l和pos_r,從開頭掃到結(jié)尾,若當(dāng)區(qū)間已經(jīng)包含t,則更新最短結(jié)果+pos_l右移,否則pos_r右移,注意當(dāng)pos_r移動到最右端時并不能立刻停止,因為pos_l或許可以繼續(xù)右移,得到更短的答案

            因為各種腦殘沒考慮到的case WA了7次才過。。。

             1 #76
             2 #Runtime: 302 ms
             3 #Memory Usage: 14 MB
             4 
             5 class Solution(object):
             6     def minWindow(self, s, t):
             7         """
             8         :type s: str
             9         :type t: str
            10         :rtype: str
            11         """
            12         dict_s ={}
            13         for i in s:
            14             if i not in dict_s:
            15                 dict_s[i] = 1
            16             else:
            17                 dict_s[i] += 1
            18         dict_t ={}
            19         for i in t:
            20             if i not in dict_t:
            21                 dict_t[i] = 1
            22             else:
            23                 dict_t[i] += 1
            24             if i not in dict_s:
            25                 return ""
            26             if dict_s[i] < dict_t[i]:
            27                 return ""
            28         pos_l = 0
            29         pos_r = 0
            30         tp_len_t = len(t)
            31         ans_l = 0
            32         ans_r = len(s)
            33         min_len = len(s)
            34         while pos_r < len(s) or tp_len_t <= 0:
            35
            36             if tp_len_t > 0:
            37                 if s[pos_r] in dict_t:
            38                     dict_t[s[pos_r]] -= 1
            39                     if dict_t[s[pos_r]] >= 0:
            40                         tp_len_t -= 1
            41                 pos_r += 1
            42             else:
            43                 if min_len > pos_r - pos_l:
            44                     ans_l = pos_l
            45                     ans_r = pos_r
            46                     min_len = ans_r - ans_l
            47                 if s[pos_l] in dict_t:
            48                     dict_t[s[pos_l]] += 1
            49                     if dict_t[s[pos_l]] > 0:
            50                         tp_len_t += 1
            51                 pos_l += 1
            52                 
            53         return s[ans_l : ans_r]
            久久久一本精品99久久精品88| 久久国产精品无码HDAV| 国产成人综合久久精品尤物| 狠狠色婷婷综合天天久久丁香| 国产精品日韩深夜福利久久| 国产成人无码精品久久久性色 | 久久91精品国产91| 99久久精品免费看国产一区二区三区| 精品久久久久久久| 亚洲精品无码久久久| 国产精品久久久久…| 国内高清久久久久久| 人妻无码精品久久亚瑟影视| 国产精品久久成人影院| 久久精品中文字幕一区| 久久成人精品| 99久久久精品免费观看国产| 亚洲国产一成久久精品国产成人综合| 久久香蕉国产线看观看精品yw| 久久99亚洲综合精品首页| 久久夜色精品国产亚洲| 中文字幕人妻色偷偷久久 | 久久精品免费网站网| 精品久久久久久久| 精品久久久久久无码专区 | 亚洲成av人片不卡无码久久| 91精品国产高清久久久久久91| 久久国产乱子伦免费精品| 久久人妻少妇嫩草AV蜜桃| 一本色道久久综合| 色青青草原桃花久久综合| 人妻无码精品久久亚瑟影视| 精品久久久久久国产牛牛app| 久久美女网站免费| 精品国产91久久久久久久| 国产69精品久久久久777| 国产成年无码久久久久毛片| …久久精品99久久香蕉国产| 成人免费网站久久久| 久久99热这里只有精品国产| 日本久久中文字幕|