当前位置:网站首页>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).
边栏推荐
- Transport layer protocol ----- UDP protocol
- Ffmpeg learning - core module
- What is a humble but profitable sideline?
- VBA fast switching sheet
- Huawei equipment is configured with OSPF and BFD linkage
- Wechat applet -- wxml template syntax (with notes)
- 15 MySQL stored procedures and functions
- How to rotate the synchronized / refreshed icon (EL icon refresh)
- openssl-1.0.2k版本升级openssl-1.1.1p
- 行列式学习笔记(一)
猜你喜欢

The difference of time zone and the time library of go language

"14th five year plan": emphasis on the promotion of electronic contracts, electronic signatures and other applications

Open source CRM customer relationship system management system source code, free sharing

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

跟着CTF-wiki学pwn——ret2libc1

20220703 week race: number of people who know the secret - dynamic rules (problem solution)

传输层协议------UDP协议

总结了 800多个 Kubectl 别名,再也不怕记不住命令了!

【DesignMode】组合模式(composite mode)
随机推荐
FFT 学习笔记(自认为详细)
Gd32f4xx UIP protocol stack migration record
[gym 102832h] [template] combination lock (bipartite game)
【DesignMode】适配器模式(adapter pattern)
Which side projects can be achieved? Is it difficult for we media to earn more than 10000 a month?
What is information security? What is included? What is the difference with network security?
【NOI模拟赛】Anaid 的树(莫比乌斯反演,指数型生成函数,埃氏筛,虚树)
数据库遇到的问题
Ffmpeg learning - core module
Key structure of ffmpeg -- AVCodecContext
转:未来,这样的组织才能扛住风险
如何解决ecology9.0执行导入流程流程产生的问题
20220703 week race: number of people who know the secret - dynamic rules (problem solution)
Mathematical model Lotka Volterra
DEJA_ Vu3d - cesium feature set 055 - summary description of map service addresses of domestic and foreign manufacturers
[SQL] SQL expansion languages of mainstream databases (T-SQL, pl/sql, pl/pgsql)
Priority queue (heap)
XML configuration file (DTD detailed explanation)
Zhongjun group launched electronic contracts to accelerate the digital development of real estate enterprises
[binary search tree] add, delete, modify and query function code implementation