Skip to content

Commit 0f40f3a

Browse files
committed
daily
1 parent 715dec0 commit 0f40f3a

File tree

4 files changed

+152
-0
lines changed

4 files changed

+152
-0
lines changed

problems/problem_0796/solution_1.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import pytest
2+
3+
4+
class Solution:
5+
def rotateString(self, s: str, goal: str) -> bool:
6+
for i in range(len(s)):
7+
if s[i:] + s[:i] == goal:
8+
return True
9+
10+
return False
11+
12+
13+
tests = [
14+
(
15+
("abcde", "cdeab"),
16+
True,
17+
),
18+
(
19+
("abcde", "abced"),
20+
False,
21+
),
22+
]
23+
24+
25+
@pytest.mark.timeout(2)
26+
@pytest.mark.parametrize(
27+
"inputs, expected",
28+
tests,
29+
)
30+
def test_validator(inputs, expected):
31+
output = Solution().rotateString(*inputs)
32+
assert output == expected

problems/problem_0796/solution_2.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import pytest
2+
3+
4+
class Solution:
5+
def rotateString(self, s: str, goal: str) -> bool:
6+
return len(s) == len(goal) and goal in s + s
7+
8+
9+
tests = [
10+
(
11+
("abcde", "cdeab"),
12+
True,
13+
),
14+
(
15+
("abcde", "abced"),
16+
False,
17+
),
18+
]
19+
20+
21+
@pytest.mark.timeout(2)
22+
@pytest.mark.parametrize(
23+
"inputs, expected",
24+
tests,
25+
)
26+
def test_validator(inputs, expected):
27+
output = Solution().rotateString(*inputs)
28+
assert output == expected

problems/problem_1233/solution_1.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from collections import defaultdict
2+
from typing import List
3+
4+
import pytest
5+
6+
7+
class Solution:
8+
class Trie:
9+
def __init__(self):
10+
self.children = defaultdict(Solution.Trie)
11+
self.word = ""
12+
13+
def removeSubfolders(self, folder: List[str]) -> List[str]:
14+
root = Solution.Trie()
15+
for path in folder:
16+
node = root
17+
sub_folders = path.split("/")
18+
for sub_folder in sub_folders[1:]:
19+
node = node.children[sub_folder]
20+
node.word = path
21+
22+
def dfs(node):
23+
if node.word:
24+
yield node.word
25+
else:
26+
for child in node.children:
27+
yield from dfs(node.children[child])
28+
29+
return list(dfs(root))
30+
31+
32+
tests = [
33+
(
34+
(["/a", "/a/b", "/c/d", "/c/d/e", "/c/f"],),
35+
["/a", "/c/d", "/c/f"],
36+
),
37+
(
38+
(["/a", "/a/b/c", "/a/b/d"],),
39+
["/a"],
40+
),
41+
(
42+
(["/a/b/c", "/a/b/ca", "/a/b/d"],),
43+
["/a/b/c", "/a/b/ca", "/a/b/d"],
44+
),
45+
]
46+
47+
48+
@pytest.mark.timeout(2)
49+
@pytest.mark.parametrize(
50+
"inputs, expected",
51+
tests,
52+
)
53+
def test_validator(inputs, expected):
54+
output = Solution().removeSubfolders(*inputs)
55+
assert output == expected

problems/problem_3163/solution_1.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import pytest
2+
3+
4+
class Solution:
5+
def compressedString(self, word: str) -> str:
6+
res = ""
7+
i = 0
8+
while i < len(word):
9+
j = i
10+
while j < len(word) and (j - i) < 9 and word[i] == word[j]:
11+
j += 1
12+
res += str(j - i) + word[i]
13+
i = j
14+
return res
15+
16+
17+
tests = [
18+
(
19+
("abcde",),
20+
"1a1b1c1d1e",
21+
),
22+
(
23+
("aaaaaaaaaaaaaabb",),
24+
"9a5a2b",
25+
),
26+
(
27+
("abcde",),
28+
"1a1b1c1d1e",
29+
),
30+
]
31+
32+
33+
@pytest.mark.timeout(2)
34+
@pytest.mark.parametrize("inputs, expected", tests)
35+
def test_validator(inputs, expected):
36+
output = Solution().compressedString(*inputs)
37+
assert output == expected

0 commit comments

Comments
 (0)