当前位置:网站首页>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).
边栏推荐
- Laser slam learning record
- Qt 一个简单的word文档编辑器
- "14th five year plan": emphasis on the promotion of electronic contracts, electronic signatures and other applications
- Cloudcompare & PCL point cloud randomly adds noise
- MySQL global lock and table lock
- Recognize the small experiment of extracting and displaying Mel spectrum (observe the difference between different y_axis and x_axis)
- 激光slam学习记录
- Permission problem: source bash_ profile permission denied
- Make a short video clip number of we media film and television. Where can I download the material?
- How to rotate the synchronized / refreshed icon (EL icon refresh)
猜你喜欢
Learn PWN from CTF wiki - ret2libc1
如何解决ecology9.0执行导入流程流程产生的问题
PV静态创建和动态创建
Single merchant v4.4 has the same original intention and strength!
用列表初始化你的vector&&initializer_list简介
云呐|公司固定资产管理系统有哪些?
MySql——CRUD
【NOI模拟赛】Anaid 的树(莫比乌斯反演,指数型生成函数,埃氏筛,虚树)
There is no network after configuring the agent by capturing packets with Fiddler mobile phones
openssl-1.0.2k版本升级openssl-1.1.1p
随机推荐
DEJA_VU3D - Cesium功能集 之 055-国内外各厂商地图服务地址汇总说明
What are the functions of Yunna fixed assets management system?
Browser local storage
用列錶初始化你的vector&&initializer_list簡介
[day39 literature extensive reading] a Bayesian perspective on magnetic estimation
Global and Chinese markets of universal milling machines 2022-2028: Research Report on technology, participants, trends, market size and share
7.5模拟赛总结
GD32F4xx uIP协议栈移植记录
MySql——CRUD
软件测试工程师必会的银行存款业务,你了解多少?
The use of El cascader and the solution of error reporting
Which side projects can be achieved? Is it difficult for we media to earn more than 10000 a month?
Make a short video clip number of we media film and television. Where can I download the material?
【QT】Qt使用QJson生成json文件并保存
亲测可用fiddler手机抓包配置代理后没有网络
Key structure of ffmpeg - avframe
Cloudcompare & PCL point cloud randomly adds noise
C reflection and type
Global and Chinese markets of POM plastic gears 2022-2028: Research Report on technology, participants, trends, market size and share
7.5 simulation summary