1598. Crawler Log Folder Easy

@problem@discussion
#Array#String#Stack



1/**
2 * [1598] Crawler Log Folder
3 *
4 * The Leetcode file system keeps a log each time some user performs a change folder operation.
5 * The operations are described below:
6 * 
7 * 	"../" : Move to the parent folder of the current folder. (If you are already in the main folder, remain in the same folder).
8 * 	"./" : Remain in the same folder.
9 * 	"x/" : Move to the child folder named x (This folder is guaranteed to always exist).
10 * 
11 * You are given a list of strings logs where logs[i] is the operation performed by the user at the i^th step.
12 * The file system starts in the main folder, then the operations in logs are performed.
13 * Return the minimum number of operations needed to go back to the main folder after the change folder operations.
14 *  
15 * Example 1:
16 * <img alt="" src="https://assets.leetcode.com/uploads/2020/09/09/sample_11_1957.png" style="width: 775px; height: 151px;" />
17 * 
18 * Input: logs = ["d1/","d2/","../","d21/","./"]
19 * Output: 2
20 * Explanation: Use this change folder operation "../" 2 times and go back to the main folder.
21 * 
22 * Example 2:
23 * <img alt="" src="https://assets.leetcode.com/uploads/2020/09/09/sample_22_1957.png" style="width: 600px; height: 270px;" />
24 * 
25 * Input: logs = ["d1/","d2/","./","d3/","../","d31/"]
26 * Output: 3
27 * 
28 * Example 3:
29 * 
30 * Input: logs = ["d1/","../","../","../"]
31 * Output: 0
32 * 
33 *  
34 * Constraints:
35 * 
36 * 	1 <= logs.length <= 10^3
37 * 	2 <= logs[i].length <= 10
38 * 	logs[i] contains lowercase English letters, digits, '.', and '/'.
39 * 	logs[i] follows the format described in the statement.
40 * 	Folder names consist of lowercase English letters and digits.
41 * 
42 */
43pub struct Solution {}
44
45// problem: https://leetcode.com/problems/crawler-log-folder/
46// discuss: https://leetcode.com/problems/crawler-log-folder/discuss/?currentPage=1&orderBy=most_votes&query=
47
48// submission codes start here
49
50impl Solution {
51    pub fn min_operations(logs: Vec<String>) -> i32 {
52        0
53    }
54}
55
56// submission codes end
57
58#[cfg(test)]
59mod tests {
60    use super::*;
61
62    #[test]
63    fn test_1598() {
64    }
65}
66


Back
© 2025 bowen.ge All Rights Reserved.