作者smart0eddie (smart0eddie)
標題Re: [閒聊] 每日leetcode
時間2024-07-10 12:17:05
2024-07-10
1598. Crawler Log Folder
The Leetcode file system keeps a log each time some user performs a change
folder operation.
The operations are described below:
"../" : Move to the parent folder of the current folder. (If you are
already in the main folder, remain in the same folder).
"./" : Remain in the same folder.
"x/" : Move to the child folder named x (This folder is guaranteed to
always exist).
You are given a list of strings logs where logs[i] is the operation performed
by the user at the ith step.
The file system starts in the main folder, then the operations in logs are
performed.
Return the minimum number of operations needed to go back to the main folder
after the change folder operations.
好像
不能
幹嘛
只能照題目要求刻一個程式去處理輸入串
class Solution {
public:
int minOperations(vector<string>& logs) {
int lv = 0;
for (auto log : logs) {
if ("./" == log) {
continue;
}
else if ("../" == log) {
lv = max(0, lv - 1);
}
else {
lv++;
}
}
return lv;
}
};
--
※ 發信站: 批踢踢實業坊(ptt.org.tw), 來自: 73.173.211.221 (美國)
※ 文章網址: https://ptt.org.tw/Marginalman/M.1720585027.A.95D
→ Rushia: 你的寫法跟我100%像 07/10 12:17