leetcode--Simplify Path
来源:互联网 发布:教育部网络培训中心 编辑:程序博客网 时间:2024/06/06 13:06
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"
.
public class Solution { public String simplifyPath(String path) { ArrayList<String> res = new ArrayList<String>();String[] arr = path.split("/");for(int i=0;i<arr.length;i++){if(arr[i].equals("")){continue;}else if(arr[i].equals(".")){continue;}else if(arr[i].equals("..")){int size = res.size();if(size!=0) res.remove(size-1);}else{res.add(arr[i]);}}String str = ""; if(res.size()==0) str="/";for(String p:res){str += "/"+p;}return str; }}
0 0
- 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
- Leetcode: Simplify Path
- LeetCode题解:Simplify Path
- [LeetCode] Simplify Path
- LeetCode Simplify Path
- cc2430的中文资料
- CGContextAddArc与CGContextAddArcToPoint参数解析
- Animation介绍加动画属性的详解
- iOS json登录服务器
- 通信中英对照表
- leetcode--Simplify Path
- 简单的JavaScript组件化实现
- SQL Server date、datetime、smalldate区别
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault)
- getting multivariate gaussian distribution from independent ones
- POJ3243 Clever Y 解 高次同余方程
- 矩形面积并 hdu 1542 Atlantis
- google.protobuf.... modul not found
- C++中使用指针访问类私有变量