[LeetCode]Simplify Path
来源:互联网 发布:好吃的肉类零食知乎 编辑:程序博客网 时间:2024/06/03 23:02
https://leetcode.com/problems/simplify-path/
string.split的时候如果两个标志之间没有值也会返回一个空字符串,stack用ArrayDeque,“/..”和“/home//test”都是合法输入
public class Solution { public String simplifyPath(String path) { if (path == null) return path; String[] arr = path.split("/"); Deque<String> stack = new ArrayDeque<>(); for (int i = 0; i < arr.length; i++) { if (arr[i].equals(".") || arr[i].length() == 0) continue; else if (arr[i].equals("..")) { if (!stack.isEmpty()) stack.pop(); } else stack.push(arr[i]); } StringBuilder sb = new StringBuilder(); while (!stack.isEmpty()) { sb.insert(0, "/" + stack.pop()); } return sb.length() == 0 ? "/" : sb.toString(); }}
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
- 一段完美实现字符串倒序的算法!
- tensorflow中关于队列使用的实验
- HDFS详解
- 【备注】【C32】《jQuery基础教程(第2版)[中文]》PDF下载
- 方方正正
- [LeetCode]Simplify Path
- 【HTML5】画小猫咪
- Shell script执行方式
- 终极肖像美容润饰PS动作
- 基于svm的中文文本自动分类系统
- Java线程和多线程(十四)——Synchronized关键字解析
- css 左边固定宽度,右边自动填充的布局,不用flex
- 2016年10月27日Ramesh Contest
- 转发与重定向