Skip to content

Latest commit

 

History

History
50 lines (36 loc) · 1.2 KB

_1100. Find K-Length Substrings With No Repeated Characters.md

File metadata and controls

50 lines (36 loc) · 1.2 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : March 10, 2025

Last updated : March 10, 2025


Related Topics : Hash Table, String, Sliding Window

Acceptance Rate : 76.09 %


Solutions

Python

class Solution:
    def numKLenSubstrNoRepeats(self, s: str, k: int) -> int:
        letters = set()
        left    = 0
        output  = 0

        for c in s :
            if c in letters :
                while s[left] != c :
                    letters.remove(s[left])
                    left += 1
                left += 1
            letters.add(c)

            while len(letters) > k :
                letters.remove(s[left])
                left += 1

            if len(letters) == k :
                output += 1

        return output