Crawler Log Folder LeetCode solution in Python
1class Solution:2def minOperations(self, logs: List[str]) -> int:3m = "../"4r = "./"5# create an empty stack6stk = []7# iterate through the list8for i in logs:9# if Move to the parent folder (../) operator occurs and stack is not empty, pop element from stack10if i == m:11if len(stk) > 0:12stk.pop()13# else if Remain in the same folder (./) operator occurs, do nothing and move to next element in list14elif i == r:15continue16# else add element to the stack17else:18stk.append(i)19# now return the size of the stack which would be the minimum number of operations needed to go back to the main folder20return len(stk)