当前位置:网站首页>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).
边栏推荐
- JS 这次真的可以禁止常量修改了!
- 多普勒效应(多普勒频移)
- Global and Chinese market of valve institutions 2022-2028: Research Report on technology, participants, trends, market size and share
- XML configuration file (DTD detailed explanation)
- 亲测可用fiddler手机抓包配置代理后没有网络
- 第16章 OAuth2AuthorizationRequestRedirectWebFilter源码解析
- USB Interface USB protocol
- 7.5 装饰器
- QT--线程
- 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?
猜你喜欢

Detailed explanation of APP functions of door-to-door appointment service

教你在HbuilderX上使用模拟器运行uni-app,良心教学!!!

MySql——CRUD

Problem solving win10 quickly open ipynb file

云呐|固定资产管理系统功能包括哪些?

CAS and synchronized knowledge

Start from the bottom structure and learn the introduction of fpga---fifo IP core and its key parameters

单商户V4.4,初心未变,实力依旧!

How much do you know about the bank deposit business that software test engineers must know?

Wechat applet -- wxml template syntax (with notes)
随机推荐
【DesignMode】组合模式(composite mode)
认识提取与显示梅尔谱图的小实验(观察不同y_axis和x_axis的区别)
Asynchronous task Whenall timeout - Async task WhenAll with timeout
【QT】Qt使用QJson生成json文件并保存
C reflection and type
总结了 800多个 Kubectl 别名,再也不怕记不住命令了!
剖面测量之提取剖面数据
XML configuration file (DTD detailed explanation)
Teach you to run uni app with simulator on hbuilderx, conscience teaching!!!
如何解决ecology9.0执行导入流程流程产生的问题
【二叉搜索树】增删改查功能代码实现
多普勒效應(多普勒頻移)
Hudi of data Lake (2): Hudi compilation
Configuring OSPF GR features for Huawei devices
Initialiser votre vecteur & initialisateur avec une liste Introduction à la Liste
openssl-1.0.2k版本升级openssl-1.1.1p
What is a humble but profitable sideline?
USB Interface USB protocol
Miaochai Weekly - 8
选择致敬持续奋斗背后的精神——对话威尔价值观【第四期】