stack&queue
来源:互联网 发布:sql无法访问数据库 编辑:程序博客网 时间:2024/05/24 06:48
71. simplify path:
简化ubuntu中的文件路径
当遇到"/../"时,需要返回上级目录,返回之间应该检查上级是否为空,若为空的话,则就代表"/"
当遇到"//"或"/./"时,不用做任何操作,这都代表的是本级目录;
遇到其它字符时,则代表的是文件夹名;
*代码处理时:字符串间的比较采用equals()方法,使用"=="比较出错.
public String simplifyPath(String path) { Stack<String> st = new Stack<String>(); String result=""; String[] str = path.split("/"); for(String temp:str){ if(temp.equals(".")||temp.length()==0) ; //均表示本级目录 else if(temp.equals("..")){ if(st.isEmpty()); //上级目录为空的情况 else st.pop(); } else st.push(temp); } if(st.isEmpty()) return "/"; else{ while(!st.isEmpty()){ result="/"+st.pop()+result; } } return result; }
0 0
- stack,queue
- Queue\Stack
- queue stack
- Stack&Queue
- stack&queue
- stack/queue
- Stack && Queue
- LeetCode[Stack]----Min Stack&Stack&Queue
- Java - Queue Stack
- Queue和Stack
- STL----stack与queue
- stack,queue,vector用法
- stack和queue详解
- stack,deque,queue对比
- [C++] Stack / queue / priority_queue
- C++ STACK Queue
- <数据结构>stack & queue
- KNOW: List, Stack, Queue
- NYOJ 123 士兵杀敌(四) (树状数组) 插线问点
- Servlet3.0学习总结(一)——使用注解标注Servlet
- 常用命令
- HttpClient使用详解
- 工厂方法模式与抽象工厂模式
- stack&queue
- 飛飛(终极版)关于贺利坚贺老师的感受和总结
- wireshark https 抓包
- B-树 C++模板类封装
- Servlet3.0学习总结(二)——使用注解标注过滤器(Filter)
- 第十五周项目二洗牌二
- 一天一条Linux指令-cd
- python 虚拟环境
- Servlet3.0学习总结(三)——基于Servlet3.0的文件上传