#1598

Crawler Log Folder

newbie · 270 · lc easy +19 · verified · 71.6% accepted · 1,544 likes · top 81%

Description

A file system begins in the main folder. Given a list of logs, where each entry is "../" (go to parent, staying if already at root), "./" (stay), or "x/" (enter child folder x), return the minimum number of steps needed to navigate back to the main folder after all operations.

Example 1:

Input: logs = ["d1/","d2/","../","d21/","./"]
Output: 2
Explanation: Use this change folder operation "../" 2 times and go back to the main folder.

Example 2:

Input: logs = ["d1/","d2/","./","d3/","../","d31/"]
Output: 3

Example 3:

Input: logs = ["d1/","../","../","../"]
Output: 0

Code

1
2
3