Skip to content

Commit 800f6c4

Browse files
committed
crawler log problem
1 parent a116555 commit 800f6c4

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from typing import List
2+
# The Leetcode file system keeps a log each time some user performs a change folder operation.
3+
4+
# The operations are described below:
5+
6+
# "../" : Move to the parent folder of the current folder. (If you are already in the main folder, remain in the same folder).
7+
# "./" : Remain in the same folder.
8+
# "x/" : Move to the child folder named x (This folder is guaranteed to always exist).
9+
# You are given a list of strings logs where logs[i] is the operation performed by the user at the ith step.
10+
11+
# The file system starts in the main folder, then the operations in logs are performed.
12+
13+
# Return the minimum number of operations needed to go back to the main folder after the change folder operations.
14+
15+
16+
class Solution:
17+
def minOperations(self, logs: List[str]) -> int:
18+
count = 0
19+
for operation in logs:
20+
if operation == './':
21+
continue
22+
elif operation == '../':
23+
if count != 0:
24+
count -= 1
25+
else:
26+
continue
27+
else:
28+
count += 1
29+
return max(count, 0)

leetcode/weekly contest problems/special_array_with_X_elements_greater_than_X.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
from typing import List
2+
# You are given an array nums of non-negative integers. nums is considered special if there exists a number x such that there are exactly x numbers in nums that are greater than or equal to x.
3+
4+
# Notice that x does not have to be an element in nums.
5+
6+
# Return x if the array is special, otherwise, return -1. It can be proven that if nums is special, the value for x is unique.
27

38

49
class Solution:

0 commit comments

Comments
 (0)