Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 32c1d60

Browse files
Create 567.py
1 parent 2ce7050 commit 32c1d60

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

‎500-1000/567.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution(object):
2+
def checkInclusion(self, s1, s2):
3+
"""
4+
:type s1: str
5+
:type s2: str
6+
:rtype: bool
7+
"""
8+
counts = collections.Counter(s1)
9+
l = len(s1)
10+
for i in xrange(len(s2)):
11+
if counts[s2[i]] > 0:
12+
l -= 1
13+
counts[s2[i]] -= 1
14+
if l == 0:
15+
return True
16+
start = i + 1 - len(s1)
17+
if start >= 0:
18+
counts[s2[start]] += 1
19+
if counts[s2[start]] > 0:
20+
l += 1
21+
return False

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /