Skip to content

Commit d4fa39a

Browse files
committed
✨feat: add 1598
1 parent b7e440d commit d4fa39a

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

Index/栈.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
| [735. 行星碰撞](https://leetcode.cn/problems/asteroid-collision/) | [LeetCode 题解链接](https://leetcode.cn/problems/asteroid-collision/solution/by-ac_oier-p4qh/) | 中等 | 🤩🤩🤩🤩🤩 |
1414
| [946. 验证栈序列](https://leetcode.cn/problems/validate-stack-sequences/) | [LeetCode 题解链接](https://leetcode.cn/problems/validate-stack-sequences/solution/by-ac_oier-84qd/) | 中等 | 🤩🤩🤩🤩 |
1515
| [1190. 反转每对括号间的子串](https://leetcode-cn.com/problems/reverse-substrings-between-each-pair-of-parentheses/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/reverse-substrings-between-each-pair-of-parentheses/solution/gong-shui-san-xie-shi-yong-shuang-duan-d-r35q/) | 中等 | 🤩🤩🤩🤩🤩 |
16+
| [1598. 文件夹操作日志搜集器](https://leetcode.cn/problems/crawler-log-folder/) | [LeetCode 题解链接](https://leetcode.cn/problems/crawler-log-folder/solution/by-ac_oier-24xb/) | 简单 | 🤩🤩🤩 |
1617
| [面试题 03.01. 三合一](https://leetcode-cn.com/problems/three-in-one-lcci/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/three-in-one-lcci/solution/yi-ti-shuang-jie-er-wei-shu-zu-yi-wei-sh-lih7/) | 简单 | 🤩🤩🤩 |
1718
| [面试题 02.05. 链表求和](https://leetcode-cn.com/problems/sum-lists-lcci/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/sum-lists-lcci/solution/by-ac_oier-v1zb/) | 中等 | 🤩🤩🤩 |
1819

Index/模拟.md

+1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@
164164
| [1582. 二进制矩阵中的特殊位置](https://leetcode.cn/problems/special-positions-in-a-binary-matrix/) | [LeetCode 题解链接](https://leetcode.cn/problems/special-positions-in-a-binary-matrix/solution/by-ac_oier-61w0/) | 简单 | 🤩🤩🤩🤩🤩 |
165165
| [1583. 统计不开心的朋友](https://leetcode-cn.com/problems/count-unhappy-friends/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/count-unhappy-friends/solution/gong-shui-san-xie-ha-xi-biao-mo-ni-ti-by-2qy0/) | 中等 | 🤩🤩🤩🤩 |
166166
| [1592. 重新排列单词间的空格](https://leetcode.cn/problems/rearrange-spaces-between-words/) | [LeetCode 题解链接](https://leetcode.cn/problems/rearrange-spaces-between-words/solution/by-ac_oier-0f5h/) | 简单 | 🤩🤩🤩🤩 |
167+
| [1598. 文件夹操作日志搜集器](https://leetcode.cn/problems/crawler-log-folder/) | [LeetCode 题解链接](https://leetcode.cn/problems/crawler-log-folder/solution/by-ac_oier-24xb/) | 简单 | 🤩🤩🤩 |
167168
| [1606. 找到处理最多请求的服务器](https://leetcode-cn.com/problems/find-servers-that-handled-most-number-of-requests/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/find-servers-that-handled-most-number-of-requests/solution/by-ac_oier-zgm6/) | 困难 | 🤩🤩🤩🤩 |
168169
| [1614. 括号的最大嵌套深度](https://leetcode-cn.com/problems/maximum-nesting-depth-of-the-parentheses/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/maximum-nesting-depth-of-the-parentheses/solution/gong-shui-san-xie-jian-dan-mo-ni-ti-by-a-pf5d/) | 简单 | 🤩🤩🤩🤩🤩 |
169170
| [1629. 按键持续时间最长的键](https://leetcode-cn.com/problems/slowest-key/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/slowest-key/solution/gong-shui-san-xie-jian-dan-mo-ni-ti-by-a-zjwb/) | 简单 | 🤩🤩🤩🤩🤩 |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
### 题目描述
2+
3+
这是 LeetCode 上的 **[1598. 文件夹操作日志搜集器](https://leetcode.cn/problems/crawler-log-folder/solution/by-ac_oier-24xb/)** ,难度为 **简单**
4+
5+
Tag : 「模拟」、「计数」、「栈」
6+
7+
8+
9+
每当用户执行变更文件夹操作时,LeetCode 文件系统都会保存一条日志记录。
10+
11+
下面给出对变更操作的说明:
12+
13+
* `"../"` :移动到当前文件夹的父文件夹。如果已经在主文件夹下,则 继续停留在当前文件夹 。
14+
* `"./"` :继续停留在当前文件夹。
15+
* `"x/"` :移动到名为 `x` 的子文件夹中。题目数据 保证总是存在文件夹 x 。
16+
17+
给你一个字符串列表 `logs` ,其中 `logs[i]` 是用户在 `ith` 步执行的操作。
18+
19+
文件系统启动时位于主文件夹,然后执行 `logs` 中的操作。
20+
21+
执行完所有变更文件夹操作后,请你找出 返回主文件夹所需的最小步数 。
22+
23+
示例 1:
24+
![](https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/09/26/sample_11_1957.png)
25+
```
26+
输入:logs = ["d1/","d2/","../","d21/","./"]
27+
28+
输出:2
29+
30+
解释:执行 "../" 操作变更文件夹 2 次,即可回到主文件夹
31+
```
32+
示例 2:
33+
![](https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/09/26/sample_22_1957.png)
34+
```
35+
输入:logs = ["d1/","d2/","./","d3/","../","d31/"]
36+
37+
输出:3
38+
```
39+
示例 3:
40+
```
41+
输入:logs = ["d1/","../","../","../"]
42+
43+
输出:0
44+
```
45+
46+
提示:
47+
* $1 <= logs.length <= 10^3$
48+
* $2 <= logs[i].length <= 10$
49+
* `logs[i]` 包含小写英文字母,数字,`'.'``'/'`
50+
* `logs[i]` 符合语句中描述的格式
51+
* 文件夹名称由小写英文字母和数字组成
52+
53+
---
54+
55+
### 模拟
56+
57+
根据题意进行模拟即可。
58+
59+
Java 代码:
60+
```Java
61+
class Solution {
62+
public int minOperations(String[] logs) {
63+
int depth = 0;
64+
for (String s : logs) {
65+
if (s.equals("../")) depth = Math.max(0, depth - 1);
66+
else if (!s.equals("./")) depth++;
67+
}
68+
return depth;
69+
}
70+
}
71+
```
72+
TypeScript 代码:
73+
```TypeScript
74+
function minOperations(logs: string[]): number {
75+
let depth = 0
76+
for (const s of logs) {
77+
if (s == "../") depth = Math.max(0, depth - 1)
78+
else if (s != "./") depth++
79+
}
80+
return depth
81+
};
82+
```
83+
* 时间复杂度:$O(n)$
84+
* 空间复杂度:$O(1)$
85+
86+
---
87+
88+
### 最后
89+
90+
这是我们「刷穿 LeetCode」系列文章的第 `No.1598` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先把所有不带锁的题目刷完。
91+
92+
在这个系列文章里面,除了讲解解题思路以外,还会尽可能给出最为简洁的代码。如果涉及通解还会相应的代码模板。
93+
94+
为了方便各位同学能够电脑上进行调试和提交代码,我建立了相关的仓库:https://github.com/SharingSource/LogicStack-LeetCode
95+
96+
在仓库地址里,你可以看到系列文章的题解链接、系列文章的相应代码、LeetCode 原题链接和其他优选题解。
97+

0 commit comments

Comments
 (0)