Simplify Path
来源:互联网 发布:剑三代练淘宝下单好吗 编辑:程序博客网 时间:2024/06/05 11: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"
.
当遇到“/../"则需要返回上级目录,需检查上级目录是否为空。
当遇到"/./"则表示是本级目录,无需做任何特殊操作。
当遇到"//"则表示是本级目录,无需做任何操作。
当遇到其他字符则表示是文件夹名,无需简化。
当字符串是空或者遇到”/../”,则需要返回一个"/"。当遇见"/a//b",则需要简化为"/a/b"。
当字符串为空或者为".",不做任何操作。当字符串不为"..",则将字符串入list。当字符串为"..", 则删除最后一个(返回上级目录)。
0 0
- Simplify Path
- Simplify Path
- Simplify Path
- Simplify Path
- Simplify Path
- Simplify Path
- Simplify Path
- Simplify Path
- Simplify Path
- Simplify Path
- Simplify Path
- Simplify Path
- Simplify Path
- Simplify Path
- Simplify Path
- Simplify Path
- Simplify Path
- Simplify Path
- angularJs 取<input type='file'>中文件名 (ng-model获取不了)
- 归并排序
- 排序学习
- 单例模式
- Bridge 模式
- Simplify Path
- codeforces 743D Chloe and pleasant prizes (DFS/树形DP)
- java多线程(第二种方式)
- 【Android 开发入门】android studio 控制台打印输出日志
- 2016.12.17 看看当当网
- Mac下配置php7运行环境
- 详解java类的生命周期
- JAVAScript中Math对象
- JavaScript闭包