mirror of
https://github.com/prdlk/leetcode.git
synced 2026-11-02 21:22:43 +00:00
feat(work): add longest‑repeating‑character‑replacement solution and rename variable in longest‑substring solution
This commit is contained in:
1 parent
31f89dd4f5
commit
5cac46a0bf
2 files changed
+64
-4
No files matched your search
@@ -45,12 +45,12 @@ class Solution:
|
||||
def lengthOfLongestSubstring(self, s: str) -> int:
|
||||
left = 0
|
||||
ans = 0
|
||||
seen = set()
|
||||
window = set()
|
||||
for right, c in enumerate(s):
|
||||
while c in seen:
|
||||
seen.remove(s[left])
|
||||
while c in window:
|
||||
window.remove(s[left])
|
||||
left += 1
|
||||
seen.add(c)
|
||||
window.add(c)
|
||||
ans = max(ans, right - left + 1)
|
||||
|
||||
return ans
|
||||
Reference in new issue
Block a user