当前位置:网站首页>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 calledx
In 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 <= 103
2 <= logs[i].length <= 10
logs[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).
边栏推荐
- The use of El cascader and the solution of error reporting
- 【NOI模拟赛】Anaid 的树(莫比乌斯反演,指数型生成函数,埃氏筛,虚树)
- 【在线聊天】原来微信小程序也能回复Facebook主页消息!
- Determinant learning notes (I)
- Huawei equipment is configured with OSPF and BFD linkage
- 软件测试工程师必会的银行存款业务,你了解多少?
- C file and folder operation
- PV static creation and dynamic creation
- 【DesignMode】组合模式(composite mode)
- Single merchant v4.4 has the same original intention and strength!
猜你喜欢
Gavin teacher's perception of transformer live class - rasa project actual combat e-commerce retail customer service intelligent business dialogue robot system behavior analysis and project summary (4
Redis high availability - master-slave replication, sentinel mode, cluster
Key structure of ffmpeg - avformatcontext
Problems encountered in the database
Yunna | what are the main operating processes of the fixed assets management system
Permission problem: source bash_ profile permission denied
FFMPEG关键结构体——AVFormatContext
用列表初始化你的vector&&initializer_list简介
关于结构体所占内存大小知识
硬件及接口学习总结
随机推荐
Chapter 16 oauth2authorizationrequestredirectwebfilter source code analysis
QT a simple word document editor
Doppler effect (Doppler shift)
[QT] QT uses qjson to generate JSON files and save them
Senparc.Weixin.Sample.MP源码剖析
Mysql - CRUD
微信小程序---WXML 模板语法(附带笔记文档)
Key structure of ffmpeg - avframe
Priority queue (heap)
[EF core] mapping relationship between EF core and C data type
[binary search tree] add, delete, modify and query function code implementation
Problems encountered in the database
Qt 一个简单的word文档编辑器
The difference of time zone and the time library of go language
What are the functions of Yunna fixed assets management system?
My colleagues quietly told me that flying Book notification can still play like this
数据库遇到的问题
如何解决ecology9.0执行导入流程流程产生的问题
硬件及接口学习总结
Hardware and interface learning summary