当前位置:网站首页>LeetCode 1598. Folder operation log collector
LeetCode 1598. Folder operation log collector
2022-07-06 00:09:00 【Daylight629】
1598. Folder operations log collector
Whenever a user performs a change folder operation ,LeetCode The file system keeps a log record .
The following is a description of the change operation :
"../": Move to the parent folder of the current folder . If it is already in the home folder , be Continue to stay in the current folder ."./": Continue to stay in the current folder **.**"x/": Move to a place calledxIn subfolders of . Subject data The folder always existsx.
Here's a list of strings logs , among logs[i] It's the user ith What to do next .
The file system starts in the home folder , And then execute logs The operation .
After all folder changes have been performed , Please find out The minimum number of steps required to return to the home folder .
Example 1:

Input :logs = ["d1/","d2/","../","d21/","./"]
Output :2
explain : perform "../" Operation change folder 2 Time , You can go back to your home folder
Example 2:

Input :logs = ["d1/","d2/","./","d3/","../","d31/"]
Output :3
Example 3:
Input :logs = ["d1/","../","../","../"]
Output :0
Tips :
1 <= logs.length <= 1032 <= logs[i].length <= 10logs[i]Contains lowercase English letters , Numbers ,'.'and'/'logs[i]Conform to the format described in the statement- The folder name consists of lowercase English letters and numbers
Two 、 Method 1
class Solution {
public int minOperations(String[] logs) {
int ans = 0;
for (String log : logs) {
if (log.charAt(0) != '.') ans++;
else if (ans != 0 && log.equals("../")) ans--;
}
return ans;
}
}
Complexity analysis
Time complexity :O(n).
Spatial complexity :O(1).
边栏推荐
- 7.5 装饰器
- 时区的区别及go语言的time库
- 微信小程序---WXML 模板语法(附带笔记文档)
- Choose to pay tribute to the spirit behind continuous struggle -- Dialogue will values [Issue 4]
- 多普勒效应(多普勒频移)
- QT a simple word document editor
- 2022.7.5-----leetcode. seven hundred and twenty-nine
- 第16章 OAuth2AuthorizationRequestRedirectWebFilter源码解析
- What if the C disk is not enough? Let's see how I can clean up 25g of temp disk space after I haven't redone the system for 4 years?
- What are Yunna's fixed asset management systems?
猜你喜欢

18. (ArcGIS API for JS) ArcGIS API for JS point collection (sketchviewmodel)

NSSA area where OSPF is configured for Huawei equipment

如何解决ecology9.0执行导入流程流程产生的问题

MySql——CRUD

【DesignMode】组合模式(composite mode)

C reflection and type

Initialize your vector & initializer with a list_ List introduction
![[designmode] composite mode](/img/9a/25c7628595c6516ac34ba06121e8fa.png)
[designmode] composite mode

Key structure of ffmpeg - avformatcontext

总结了 800多个 Kubectl 别名,再也不怕记不住命令了!
随机推荐
Initialize your vector & initializer with a list_ List introduction
Mathematical model Lotka Volterra
什么叫做信息安全?包含哪些内容?与网络安全有什么区别?
Learn PWN from CTF wiki - ret2libc1
Ffmpeg learning - core module
【在线聊天】原来微信小程序也能回复Facebook主页消息!
FFMPEG关键结构体——AVFrame
20220703 week race: number of people who know the secret - dynamic rules (problem solution)
[noi simulation] Anaid's tree (Mobius inversion, exponential generating function, Ehrlich sieve, virtual tree)
剖面测量之提取剖面数据
What is information security? What is included? What is the difference with network security?
【DesignMode】装饰者模式(Decorator pattern)
QT -- thread
Yunna | what are the main operating processes of the fixed assets management system
2022.7.5-----leetcode.729
Huawei equipment configuration ospf-bgp linkage
QT QPushButton details
Qt 一个简单的word文档编辑器
传输层协议------UDP协议
Configuring OSPF load sharing for Huawei devices