麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發(fā)設計 > 正文

53:Simplify Path

2019-11-06 08:50:58
字體:
來源:轉載
供稿:網(wǎng)友

題目:Given an absolute path for a file (Unix-style), simplify it. For example, path = “/home/”, => “/home” path = “/a/./b/../../c/”, => “/c” Corner Cases: ? Did you consider the case where path = “/../”? In this case, you should return “/”. ? Another corner case is the path might contain multiple slashes ‘/’ together, such as “/home//foo/”. In this case, you should ignore redundant slashes and return “/home/foo”.

下面解法代碼的思想及編寫參考了網(wǎng)址https://github.com/soulmachine/leetcode#leetcode題解題目

代碼如下:

/ 時間復雜度 O(n),空間復雜度 O(n)class Solution {public: string simplifyPath(const string& path) { vector<string> dirs; // 當做棧 for (auto i = path.begin(); i != path.end(); ) { ++i; auto j = find(i, path.end(), '/'); auto dir = string(i, j); if (!dir.empty() && dir != '.') { // 當有連續(xù) '///' 時,dir 為空 if (dir == '..') { if (!dirs.empty()) dirs.pop_back(); } else dirs.push_back(dir); i = j; } ostringstream out; if (dirs.empty()) out << "/"; else { for (auto dir : dirs) out << "/" << dir; } return out.str(); }};
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 美女黄色影院 | 国产羞羞视频在线免费观看 | 污视频在线免费播放 | 一级成人欧美一区在线观看 | 黄色三级网站 | 91精品国产日韩91久久久久久360 | 日本黄色免费片 | 久久综合久久美利坚合众国 | 亚洲电影在线观看高清免费 | 在线观看视频毛片 | 视频一区二区视频 | 91av久久| 成人一级在线 | 国产高潮失禁喷水爽到抽搐视频 | 欧美特黄a| 操碰 | 免费毛片在线 | 中文字幕www. | 久久久久久久亚洲精品 | 亚洲一区在线国产 | 亚洲91网| 成年人在线视频观看 | 老子午夜影院 | 亚洲综人网| 欧美一级毛片欧美一级成人毛片 | 久久亚色 | 视频在线中文字幕 | 强伦女教师视频 | 欧美一级黄视频 | 欧美成人精品不卡视频在线观看 | 亚洲精品wwww | 免费播放欧美毛片 | 国产精品成人av片免费看最爱 | 欧美日韩在线视频一区 | 狠狠干网站| 欧美 日韩 中文 | 欧美aaaaa一级毛片在线 | 在线天堂中文在线资源网 | 欧美黄色一级片视频 | 天天操天天骑 | 999久久久久久 |