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

            因為各種腦殘沒考慮到的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]
            人妻无码中文久久久久专区| 狠狠色婷婷综合天天久久丁香 | 欧美日韩中文字幕久久伊人| 91精品国产综合久久久久久| 天天久久狠狠色综合| 久久久国产精品| 中文精品久久久久人妻不卡| 青青草国产成人久久91网| 久久久青草青青国产亚洲免观| 久久精品国产亚洲AV影院| 国产Av激情久久无码天堂| 久久精品国产一区二区三区| 一本一道久久综合狠狠老| 国产精品美女久久久久AV福利| 久久精品国产男包| 久久国产精品一区| 999久久久免费精品国产| 久久久久久精品无码人妻| 青青国产成人久久91网| 午夜人妻久久久久久久久| 欧美午夜精品久久久久久浪潮| 久久AV高清无码| 无码人妻久久一区二区三区蜜桃 | 一级做a爰片久久毛片16| 亚洲AV无码久久| 久久无码AV中文出轨人妻| 亚洲国产成人精品久久久国产成人一区二区三区综 | 久久久久无码国产精品不卡| 久久国产高清字幕中文| 人妻精品久久无码区| 18岁日韩内射颜射午夜久久成人| 久久人人爽人人爽人人片AV东京热| 99久久99这里只有免费的精品| 久久九九兔免费精品6| 亚洲午夜精品久久久久久app| 国产91久久综合| 国产精品成人无码久久久久久 | 久久精品成人免费网站| 久久狠狠高潮亚洲精品| 欧美亚洲色综久久精品国产| 日本久久久久亚洲中字幕|