Re: [閒聊] 每日leetcode已回收

看板Marginalman作者 (smart0eddie)時間1年前 (2024/07/10 12:17), 編輯推噓0(002)
留言2則, 2人參與, 1年前最新討論串470/1554 (看更多)
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.cc), 來自: 73.173.211.221 (美國) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1720585027.A.95D.html

07/10 12:17, 1年前 , 1F
你的寫法跟我100%像
07/10 12:17, 1F

07/10 12:28, 1年前 , 2F
大師
07/10 12:28, 2F
文章代碼(AID): #1cZWj3bT (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1cZWj3bT (Marginalman)