加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

leetcode-hard-array-76. Minimum Window Substring -NO

发布时间:2020-12-14 03:57:04 所属栏目:Windows 来源:网络整理
导读:mycode 不会。。 ? 参考: class Solution(object): def minWindow(self,s,t): """ :type s: str :type t: str :rtype: str """ count1 = collections.defaultdict(int) count2 = [] for char in t: count1[char] += 1 count2.append(char) count = len(t) s

mycode

不会。。

?

参考:

class Solution(object):
    def minWindow(self,s,t):
        """
        :type s: str
        :type t: str
        :rtype: str
        """
        count1 = collections.defaultdict(int)
        count2 = []
        for char in t:
            count1[char] += 1
            count2.append(char)

        count = len(t)
        start = 0
        minSize = len(s) + 1
        minStart = 0

        for end in range(len(s)):
            if s[end] in count2 :
                #print(end,count1,count2,count)
                count1[s[end]] -= 1
                if count1[s[end]] >= 0:  #<=0时表示出现了多余的t中要求的元素,比如t中两个A,现在出现了第三个A,所以没必要count-1
                    count -= 1
                if count == 0:
                    while True:                      
                        if s[start] in count2  :
                            if count1[s[start]] < 0:  #s中第一个出现t中元素的位置可以被更换啦
                                count1[s[start]] += 1
                            else:  #
                                print(start) 
                                break
                        start += 1
                    if minSize > end - start + 1:
                        minSize = end - start + 1
                        minStart = start
                #print(end,count)
             
        if minSize < len(s) + 1:
            return s[minStart:minStart + minSize]
        else:
            return ‘‘    
        
        class Solution(object):
    def minWindow(self,count)
                count1[s[end]] -= 1
                if count1[s[end]] >= 0:
                    count -= 1
                if count == 0:
                    while True:
                      
                        if s[start] in count2  :
                            if count1[s[start]] < 0:
                                count1[s[start]] += 1
                            else:
                                print(start)
                                break
                        start += 1
                    if minSize > end - start + 1:
                        minSize = end - start + 1
                        minStart = start
                #print(end,count)
             
        if minSize < len(s) + 1:
            return s[minStart:minStart + minSize]
        else:
            return ‘‘    
        
        

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读