71.Simplify Path
来源:互联网 发布:中老年女式毛衣淘宝 编辑:程序博客网 时间:2024/06/03 20:26
71.Simplify Path
题目描述:Given an absolute path for a file (Unix-style), simplify it.
For example,
path ="/home/"
, =>"/home"
path ="/a/./b/../../c/"
, =>"/c"
题目含义:简化path
代码
package String;import java.util.*;/*** @Author OovEver* @Date 2017/12/9 16:05*/public class LeetCode71 { public String simplifyPath(String path) { Deque<String> stack = new LinkedList<>(); Set<String> skip = new HashSet<>(Arrays.asList("..", ".", "")); for (String dir : path.split("/")) { if (dir.equals("..") && !stack.isEmpty()) stack.pop(); else if (!skip.contains(dir)) stack.push(dir); } String res = ""; for (String dir : stack) res = "/" + dir + res; return res.isEmpty() ? "/" : 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
- c++学习总结2
- 高中数学?
- 电子商务网站(模块化布局)实战开发
- 最小二乘法线性拟合计算器
- [JZOJ5500]【清华集训2017模拟12.10】营养餐
- 71.Simplify Path
- springmvc中@valid的分组校验
- auto
- 160
- 哈希表
- 51nod 1770 数数字
- 蓝桥杯 算法提高 9-2 文本加密
- spring boot shiro redis整合
- 编程中的脚手架是什么意思?