Skip to content

Commit 84e2cec

Browse files
Merge pull request #21 from paxtonfitzpatrick/main
solution and notes for problem 1598
2 parents 7cbcd9d + eb09620 commit 84e2cec

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

problems/1598/paxtonfitzpatrick.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# [Problem 1598: Crawler Log Folder](https://leetcode.com/problems/crawler-log-folder/description/?envType=daily-question)
2+
3+
## Initial thoughts (stream-of-consciousness)
4+
5+
- looks like another easy one...
6+
- I'll just iterate through the list and keep track of how many steps we currently are from the main folder.
7+
- oh I wonder what Pyhon version leetcode uses. If 3.10+, this is a good use case for structural pattern matching
8+
- cool, [looks like it's 3.11](https://support.leetcode.com/hc/en-us/articles/360011833974-What-are-the-environments-for-the-programming-languages)
9+
- huh, some other useful info from that page: "most" standard library modules are already imported, and also you can `import sortedcontainers`, which is 3rd party
10+
- no idea how the execution speed of `match`/`case` statements compares to that of standard `if`/`elif`/`else`. My guess would be any difference is minimal, but if anything it might be a little faster since it's a more specific "case" of a conditional, so the instructions it's compiled to might be more specific? OTOH it's a newer feature so it might not be as optimized.
11+
- I *could* pre-filter the list and remove all `"./"`'s, since they do nothing, but I doubt this would actually be faster since it'd essentially entail looping through twice
12+
- unless I converted the whole list object to a string, used `.replace()`, and converted the result back to a list. Maybe this would ultimately save some time if the list was very long *and* contained a sufficiently large number of `"./"`'s... but I think it's probably not worth it in the general case.
13+
14+
## Refining the problem, round 2 thoughts
15+
16+
## Attempted solution(s)
17+
18+
```python
19+
class Solution:
20+
def minOperations(self, logs: List[str]) -> int:
21+
steps_away = 0
22+
for log in logs:
23+
match log:
24+
case "../":
25+
if steps_away > 0:
26+
steps_away -= 1
27+
case "./":
28+
continue
29+
case _:
30+
steps_away += 1
31+
return steps_away
32+
```
33+
34+
![](https://github.com/paxtonfitzpatrick/leetcode-solutions/assets/26118297/40647d9b-543e-47f9-b97b-a6f182c0140d)

0 commit comments

Comments
 (0)