LeetCoce-71-Simplify Path(栈)-Medium
来源:互联网 发布:淘宝卖steam游戏 编辑:程序博客网 时间:2024/06/09 14:13
题意理解:
简化路径名;
题目分析:
1. 注意 “.” 、".."特殊字符的处理;
2. 运用栈;
解题代码:
public class Solution { public String simplifyPath(String path) { String ans="/"; if(path.length()==0){ return ans; } Stack<String> stack=new Stack<String>(); String[] splitVal=path.split("/"); for(int i=0; i<splitVal.length;i++){ if(splitVal[i].equals(".")){ continue; }else if(splitVal[i].equals("..")){ if(!stack.empty()){ stack.pop(); } }else if(splitVal[i].length()!=0){ stack.push(splitVal[i]); } } while(!stack.empty()){ if(ans.equals("/")){ ans+=stack.pop(); }else{ ans="/"+stack.pop()+ans; } } return ans; }}
0 0
- LeetCoce-71-Simplify Path(栈)-Medium
- LeetCode 71 Simplify Path (栈)
- Leetcode 71. Simplify Path (Medium) (cpp)
- LeetCode 71 Simplify Path
- LeetCode(71) Simplify Path
- [leetcode 71] Simplify Path
- leetcode || 71、Simplify Path
- LeetCode(71) Simplify Path
- 71 Simplify Path
- leetcode 71: Simplify Path
- 【leetcode】【71】Simplify Path
- LeetCode_OJ【71】Simplify Path
- leetcode 71 Simplify Path
- LeetCode 71 Simplify Path
- Leetcode 71 Simplify Path
- leetcode-71 simplify path
- LeetCode #71 Simplify Path
- FTPrep, 71 Simplify Path
- [安装报错]Android Studio报错 'reg'不是内部或外部命令,也不是可运行的程序或批处理文件。
- 【BZOJ1030】[JSOI2007]文本生成器【AC自动机】【计数DP】
- JavaScript的闭包理解
- day07
- UBUNTU 15.10 CAFFE安装教程(测试可用)
- LeetCoce-71-Simplify Path(栈)-Medium
- 自己用的的KVM相关的技术点的总结
- 关于日期选择器的一些小应用
- 得到系统的时间 并转化成NSString NSDate
- 事件
- wordpress教程
- Sparak-Streaming基于Offset消费Kafka数据
- 题三 画线
- 深入剖析Java中的装箱和拆箱