0
点赞
收藏
分享

微信扫一扫

LeetCode题解(1100):长度为K的无重复字符子串(Python)


题目:​​原题链接​​(中等)

标签:滑动窗口、哈希表、字符串

解法

时间复杂度

空间复杂度

执行用时

Ans 1 (Python)

64ms (59.14%)

Ans 2 (Python)

Ans 3 (Python)

解法一:

class Solution:
def numKLenSubstrNoRepeats(self, s: str, k: int) -> int:
count = [0] * 26

if len(s) < k:
return 0

for i in range(k):
a = ord(s[i]) - 97
count[a] += 1

ans = 1 if max(count) <= 1 else 0

for i in range(k, len(s)):
a1 = ord(s[i]) - 97
count[a1] += 1
a2 = ord(s[i - k]) - 97
count[a2] -= 1
if max(count) <= 1:
ans += 1

return


举报

相关推荐

0 条评论