Leetcode 71. Simplify Path (Medium) (cpp)
来源:互联网 发布:实际投资算法 编辑:程序博客网 时间:2024/06/17 03:23
Leetcode 71. Simplify Path (Medium) (cpp)
Tag: Stack, String
Difficulty: Medium
/*71. Simplify Path (Medium)Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"click to show corner cases.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".*/class Solution {public:string simplifyPath(string path) {string res = "", token;stringstream ss(path);vector<string> pos;while(getline(ss, token, '/')){if(token == "." || token == "") continue;else if(token==".."){if(!pos.empty()) pos.pop_back();}else pos.push_back(token);}if(pos.empty()) return "/";for(string i : pos)res = res + '/' + i;return res;}};
0 0
- Leetcode 71. Simplify Path (Medium) (cpp)
- LeetCode 71. Simplify Path
- LeetCode --- 71. Simplify Path
- [Leetcode] 71. Simplify Path
- [leetcode] 71.Simplify Path
- [leetcode] 71.Simplify Path
- Leetcode 71. Simplify Path
- LeetCode 71. Simplify Path
- Leetcode 71. Simplify Path
- 71. Simplify Path LeetCode
- leetcode 71. Simplify Path
- LeetCode 71. Simplify Path
- LeetCode 71. Simplify Path
- Leetcode 71. Simplify Path
- [leetcode] 71. Simplify Path
- LeetCode 71. Simplify Path
- LeetCode - 71. Simplify Path
- [LeetCode] 71. Simplify Path
- 在Windows和Linux中安装和配置Java…
- java IO(File类、字节流与字符流、字节字符转换流)
- 16张扑克逻辑思维问题详解
- Redis之key
- NSString、NSMutableString操作
- Leetcode 71. Simplify Path (Medium) (cpp)
- HDU 1712 ACboy needs your help (分组背包入门题)
- Spring使用静态工厂方法创建Bean
- 小技巧--视频编辑会声会影安装
- Error vs Exception的区别?
- 高效开发习惯
- http协议
- 二维计算几何模板--圆
- Ubuntu建立wifi热点(支持Android手机)