aboutsummaryrefslogtreecommitdiff
path: root/crawler_log_folder.py
diff options
context:
space:
mode:
Diffstat (limited to 'crawler_log_folder.py')
-rw-r--r--crawler_log_folder.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/crawler_log_folder.py b/crawler_log_folder.py
new file mode 100644
index 0000000..da1f69a
--- /dev/null
+++ b/crawler_log_folder.py
@@ -0,0 +1,28 @@
+# 1598. Crawler Log Folder
+from functools import reduce
+
+"""
+the leetcode file system keeps a log each time some user performs a change
+folder operation. the operations are described below. "../" move to the
+parent folder of the current folder. if you are already in the main folder,
+remain in the same folder. "./" remain in the same folder. "x/" move to the
+child folder named 'x' which is guaranteed to exist. you are given a list of
+strings 'logs' where 'logs[i]' is the operation performed by the user at the
+i'th step.
+"""
+
+
+class Solution(object):
+ def minOperations(self, logs):
+ """
+ :type logs: List[str]
+ :rtype: int
+ """
+ return reduce(lambda depth, folder: max(0, depth - folder.rfind(".")), logs, 0)
+
+
+if __name__ == "__main__":
+ obj = Solution()
+ print(obj.minOperations(logs=["d1/", "d2/", "../", "d21/", "./"]))
+ print(obj.minOperations(logs=["d1/", "d2/", "./", "d3/", "../", "d31/"]))
+ print(obj.minOperations(logs=["d1/", "../", "../", "../"]))