当前位置:网站首页>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).
边栏推荐
- MySql——CRUD
- The difference of time zone and the time library of go language
- 多普勒效應(多普勒頻移)
- USB Interface USB protocol
- Determinant learning notes (I)
- 从底层结构开始学习FPGA----FIFO IP核及其关键参数介绍
- China Jinmao online electronic signature, accelerating the digitization of real estate business
- 单商户V4.4,初心未变,实力依旧!
- Huawei equipment configuration ospf-bgp linkage
- Global and Chinese markets of universal milling machines 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢

用列表初始化你的vector&&initializer_list简介

PV static creation and dynamic creation

MySQL functions

Permission problem: source bash_ profile permission denied

Knowledge about the memory size occupied by the structure

XML configuration file (DTD detailed explanation)

时区的区别及go语言的time库

Qt QPushButton详解
![Choose to pay tribute to the spirit behind continuous struggle -- Dialogue will values [Issue 4]](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
Choose to pay tribute to the spirit behind continuous struggle -- Dialogue will values [Issue 4]

多普勒效應(多普勒頻移)
随机推荐
上门预约服务类的App功能详解
多普勒效应(多普勒频移)
China Jinmao online electronic signature, accelerating the digitization of real estate business
Problem solving win10 quickly open ipynb file
"14th five year plan": emphasis on the promotion of electronic contracts, electronic signatures and other applications
总结了 800多个 Kubectl 别名,再也不怕记不住命令了!
多普勒效應(多普勒頻移)
Global and Chinese market of digital serial inverter 2022-2028: Research Report on technology, participants, trends, market size and share
What are Yunna's fixed asset management systems?
Choose to pay tribute to the spirit behind continuous struggle -- Dialogue will values [Issue 4]
shardingsphere源码解析
[noi simulation] Anaid's tree (Mobius inversion, exponential generating function, Ehrlich sieve, virtual tree)
Gd32f4xx UIP protocol stack migration record
提升工作效率工具:SQL批量生成工具思想
7.5 装饰器
转:未来,这样的组织才能扛住风险
Which side projects can be achieved? Is it difficult for we media to earn more than 10000 a month?
Browser local storage
认识提取与显示梅尔谱图的小实验(观察不同y_axis和x_axis的区别)
【NOI模拟赛】Anaid 的树(莫比乌斯反演,指数型生成函数,埃氏筛,虚树)