当前位置:网站首页>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).
边栏推荐
猜你喜欢

Miaochai Weekly - 8
![[online chat] the original wechat applet can also reply to Facebook homepage messages!](/img/d2/1fd4de4bfd433ed397c236ddb97a66.png)
[online chat] the original wechat applet can also reply to Facebook homepage messages!

About the slmgr command

Browser local storage

Huawei equipment configuration ospf-bgp linkage

关于slmgr命令的那些事

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

Priority queue (heap)

Laser slam learning record
![[designmode] Decorator Pattern](/img/65/457e0287383d0ca9a28703a63b4e1a.png)
[designmode] Decorator Pattern
随机推荐
Detailed explanation of APP functions of door-to-door appointment service
USB Interface USB protocol
"14th five year plan": emphasis on the promotion of electronic contracts, electronic signatures and other applications
openssl-1.0.2k版本升级openssl-1.1.1p
Global and Chinese market of digital serial inverter 2022-2028: Research Report on technology, participants, trends, market size and share
PV静态创建和动态创建
Teach you to run uni app with simulator on hbuilderx, conscience teaching!!!
Key structure of ffmpeg -- AVCodecContext
C reflection and type
QT -- thread
[Luogu p3295] mengmengda (parallel search) (double)
激光slam学习记录
权限问题:source .bash_profile permission denied
数据库遇到的问题
China Jinmao online electronic signature, accelerating the digitization of real estate business
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
Hudi of data Lake (2): Hudi compilation
教你在HbuilderX上使用模拟器运行uni-app,良心教学!!!
Recognize the small experiment of extracting and displaying Mel spectrum (observe the difference between different y_axis and x_axis)
C # input how many cards are there in each of the four colors.