567Permutation in String
来源:互联网 发布:nginx 配置指定目录 编辑:程序博客网 时间:2024/05/24 22:45
class Solution(object):
def checkInclusion(self, s1, s2):
"""
:type s1: str
:type s2: str
:rtype: bool
"""
l1, l2 = len(s1), len(s2)
c1 = collections.Counter(s1)
c2 = collections.Counter()
cnt = 0
p = q = 0
while q < l2:
c2[s2[q]] += 1
if c1[s2[q]] == c2[s2[q]]:
cnt += 1
if cnt == len(c1):
return True
q += 1
if q - p + 1 > l1:
if c1[s2[p]] == c2[s2[p]]:
cnt -= 1
c2[s2[p]] -= 1
if c2[s2[p]] == 0:
del c2[s2[p]]
p += 1
def checkInclusion(self, s1, s2):
"""
:type s1: str
:type s2: str
:rtype: bool
"""
l1, l2 = len(s1), len(s2)
c1 = collections.Counter(s1)
c2 = collections.Counter()
cnt = 0
p = q = 0
while q < l2:
c2[s2[q]] += 1
if c1[s2[q]] == c2[s2[q]]:
cnt += 1
if cnt == len(c1):
return True
q += 1
if q - p + 1 > l1:
if c1[s2[p]] == c2[s2[p]]:
cnt -= 1
c2[s2[p]] -= 1
if c2[s2[p]] == 0:
del c2[s2[p]]
p += 1
return False
http://bookshadow.com/leetcode/
阅读全文
0 0
- 567Permutation in String
- LeetCode #567 Permutation in String
- LeetCode[567]Permutation in String(Java)
- Permutation in String
- 567. Permutation in String
- Permutation in String
- LeetCode567. Permutation in String
- 567. Permutation in String
- 567. Permutation in String
- 567. Permutation in String
- [leetcode]567. Permutation in String
- 567. Permutation in String Medium
- [leetcode] 567. Permutation in String
- 【LeetCode】567. Permutation in String
- [LeetCode] 567. Permutation in String
- Leetcode 567. Permutation in String
- 567. Permutation in String 字符串置换
- Leetcode之Permutation in String 问题
- 标签控件中显示对话框出现的问题及解决方法
- java——类——内部类
- System.NotSupportedException: 不支持给定路径的格式。
- LSMW批处理使用方法(11)_步骤14、15
- 生成字符串
- 567Permutation in String
- 以太网口-RJ45
- LeetCode 26. Remove Duplicates from Sorted Array
- Vue-高级讲师之笔记01
- hibernate防止sql注入的方法
- 阿里巴巴Dubbo实现的源码分析
- 第十八周:( LeetCode621)Task Scheduler(c++)
- Scikit-learn 秘籍 第五章 模型后处理
- Golang测试用例test