7 lines slide window solution in Python


  • 0
    Q
    class Solution(object):
        def checkInclusion(self, s1, s2):
            c1, c2 = collections.Counter(s1), collections.Counter(s2[0:(len(s1)-1)])
            for i in range(len(s2) - len(s1) + 1):
                c2[s2[i+len(s1) - 1]] += 1
                if len(c1 - c2) == 0:
                    return True
                c2[s2[i]] -= 1
            return False
    
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.