Simplify Path
来源:互联网 发布:ccer金融数据库 编辑:程序博客网 时间:2024/05/22 14:19
public class Solution { public String simplifyPath(String path) {if (path == null || path.length() == 0) { return "";}Stack<String> stack = new Stack<>();String[] strs = path.split("/");for (String str: strs) { if (!str.equals("") && !str.equals(".")) { if (str.equals("..")) { if (!stack.isEmpty()) { stack.pop(); } } else { stack.push(str); } }}StringBuilder sb = new StringBuilder();while (!stack.isEmpty()) { sb.insert(0, stack.pop()); sb.insert(0, "/");}if (sb.length() == 0) { return "/";} else { return sb.toString();} }}
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
- 100多个优秀的互联网编程学习平台整理。
- UIButton无法响应点击事件
- Find the Celebrity
- Meeting Rooms II
- Maximum Size Subarray Sum Equals k
- Simplify Path
- comment/uncomment lines in Vim
- 查看CPU支持的指令集
- 《c primer plus》第一个程序first.c的编辑,编译与输出
- bitset
- Leetcode 383. Ransom Note
- Zookeeper Java客户端API的使用
- JavaScript模拟线程池案例:超市收银台
- 让程序清晰可读,并在vim中设置行号