71. Simplify Path
来源:互联网 发布:linux zip命令 密码 编辑:程序博客网 时间:2024/05/16 09:17
题目
Given an absolute path for a file (Unix-style), simplify it.
For example,
path = “/home/”, => “/home”
path = “/a/./b/../../c/”, => “/c”
思路
本题如果会用getline这个C++库函数,那么问题就简单了
代码
class Solution {public: string simplifyPath(string path) { string res, tmp; vector<string> stk; stringstream ss(path); while(getline(ss,tmp,'/')) { if (tmp == "" or tmp == ".") continue; if (tmp == ".." and !stk.empty()) stk.pop_back(); else if (tmp != "..") stk.push_back(tmp); } for(auto str : stk) res += "/"+str; return res.empty() ? "/" : res;}};
阅读全文
0 0
- LeetCode 71. Simplify Path
- LeetCode --- 71. Simplify Path
- [Leetcode] 71. Simplify Path
- [leetcode] 71.Simplify Path
- 71.Simplify Path
- 71.Simplify Path
- 71. Simplify Path
- [leetcode] 71.Simplify Path
- 71. Simplify Path
- Leetcode 71. Simplify Path
- LeetCode 71. Simplify Path
- Leetcode 71. Simplify Path
- 71. Simplify Path LeetCode
- 71. Simplify Path
- 71. Simplify Path
- 71. Simplify Path
- 71. Simplify Path
- leetcode 71. Simplify Path
- android 5.0修改插电显示电池百分比,拔掉不显示问题
- 最长连续递增子序列
- 各大地图API关于逆地理位置编码
- cf434 div.2 A. k-rounding
- 创建多线程有几种方法?如何创建线程?
- 71. Simplify Path
- [POJ1155]TELE(树形dp)
- VS2017+Opencv3.3+Opencv_contribute编译
- 01背包和完全背包
- face-alignment:用 pytorch 实现的 2D 和 3D 人脸对齐库
- ARM裸机编程需要知道的汇编知识1---可编程逻辑器件
- power
- 欢迎使用CSDN-markdown编辑器
- Sqoop