Skip to content

Commit 169c74e

Browse files
Merge pull request #6 from codewithme-py/feat/longest-substring-without-repeating-characters-0003
problem solution & test 0003
2 parents 58a7b5c + 8b18d90 commit 169c74e

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

display_runtime.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def lengthOfLongestSubstring(self, s: str) -> int:
3+
if not s:
4+
return 0
5+
left_border, max_len = 0, 0
6+
actual_set = set()
7+
for right_border, char in enumerate(s):
8+
while char in actual_set:
9+
actual_set.remove(s[left_border])
10+
left_border += 1
11+
actual_set.add(char)
12+
max_len = max(max_len, right_border - left_border + 1)
13+
return max_len
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import pytest
2+
3+
from solutions.longest_substring_without_repeating_characters_0003 import Solution
4+
5+
6+
@pytest.mark.parametrize("args, expected", [
7+
("abcabcbb", 3), ("bbbbb", 1), ("pwwkew", 3), ("", 0), ("a", 1),
8+
("au", 2), ("dvdf", 3), ("tmmzuxt", 5), ("anviaj", 5), ("ohvhjdml", 6),
9+
("qrsvbspk", 5), ("", 0), ("a", 1), ("au", 2), ("dvdf", 3),
10+
("tmmzuxt", 5), ("anviaj", 5), ("ohvhjdml", 6), ("qrsvbspk", 5),
11+
("", 0), ("a", 1), ("au", 2), ("dvdf", 3), ("tmmzuxt", 5),
12+
("anviaj", 5), ("ohvhjdml", 6), ("qrsvbspk", 5),
13+
])
14+
def test_solution(args: str, expected: int) -> None:
15+
sol = Solution()
16+
assert sol.lengthOfLongestSubstring(args) == expected

0 commit comments

Comments
 (0)