leetcode---simplify-path---字符串
来源:互联网 发布:对付淘宝无良卖家 编辑:程序博客网 时间:2024/05/23 02:17
题目描述
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) { vector<string> ans; stringstream sin(path); string tmp; while(getline(sin, tmp, '/')) { if(tmp == "" || tmp == ".") continue; else if(tmp == ".." && !ans.empty()) ans.pop_back(); else if(tmp != "..") ans.push_back(tmp); } string s = ""; for(string st : ans) s += "/" + st; return s == "" ? "/" : s; }};
阅读全文
0 0
- leetcode---simplify-path---字符串
- [leetcode] 【字符串】71. Simplify Path
- leetcode:字符串之Simplify Path
- leetcode -- Simplify Path -- 字符串处理的题目
- LeetCode: Simplify Path
- LeetCode Simplify Path
- LeetCode : Simplify Path
- [Leetcode] Simplify Path
- [leetcode] simplify path
- [LeetCode] Simplify Path
- leetcode 100: Simplify Path
- [leetcode]Simplify Path
- [LeetCode]Simplify Path
- [leetCode] Simplify Path
- [leetcode]Simplify Path
- [leetcode] Simplify Path
- [LeetCode] Simplify Path
- leetcode simplify path
- 使用qsort函数排序各类型数据
- 曹老师讲课有感
- va_list简单介绍及初步实现printf函数
- Linux下简单又高可用seaweedfs文件存储服务器搭建及应用
- CentOS下Docker安装和centos+jdk镜像构建与jar包在镜像中启动
- leetcode---simplify-path---字符串
- 设计模式的理解
- 用Construct 2制作游戏(二)
- Vulkan规范:第九章 9.2
- java8特性:Collectors.groupingBy进行分组、排序等操作
- jQuery 中 ajax 的 complete 和 success 有什么区别
- Magento中后台form中的link类型的使用
- 两数交换
- git 修改作者名称和作者邮箱