Skip to content

Commit d07a84f

Browse files
author
William Grolleau
committed
daily
1 parent 71ac94b commit d07a84f

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

problems/problem_1598/solution_1.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import pytest
2+
from typing import List
3+
4+
5+
class Solution:
6+
def minOperations(self, logs: List[str]) -> int:
7+
res = 0
8+
for log in logs:
9+
if log == "../":
10+
res = max(0, res - 1)
11+
elif log == "./":
12+
continue
13+
else:
14+
res += 1
15+
return res
16+
17+
18+
tests = [
19+
(
20+
(["d1/", "d2/", "../", "d21/", "./"],),
21+
2,
22+
),
23+
(
24+
(["d1/", "d2/", "./", "d3/", "../", "d31/"],),
25+
3,
26+
),
27+
(
28+
(["d1/", "../", "../", "../"],),
29+
0,
30+
),
31+
]
32+
33+
34+
@pytest.mark.timeout(2)
35+
@pytest.mark.parametrize(
36+
"inputs, expected",
37+
tests,
38+
)
39+
def test_validator(inputs, expected):
40+
output = Solution().minOperations(*inputs)
41+
assert output == expected

0 commit comments

Comments
 (0)