71. Simplify Path
Given an absolute path for a file (Unix-style), simplify it.
For example,
path = "/home/"
, => "/home"
path = "/a/./b/../../c/"
, => "/c"
题目含义:简化unix路径
1 public String simplifyPath(String path) { 2 Stack<String > stack = new Stack<>(); 3 List<String> skip = Arrays.asList("..",".",""); 4 for (String str:path.split("/")) 5 { 6 if (str.equals("..") && !stack.isEmpty()) stack.pop(); 7 else if (!skip.contains(str)) stack.push(str); 8 } 9 String result=""; 10 for (String item:stack) 11 { 12 result += "/" + item; 13 } 14 return result.isEmpty()?"/":result; 15 }
转载于:https://www.cnblogs.com/wzj4858/p/7685305.html
71. Simplify Path相关推荐
- LeetCode 71. Simplify Path
LeetCode 71. Simplify Path 本博客转载自:https://blog.csdn.net/makuiyu/article/details/44497901 Solution1:没 ...
- [LeetCode]--71. Simplify Path
Given an absolute path for a file (Unix-style), simplify it. For example, path = "/home/", ...
- [Leetcode] Simplify Path
Given an absolute path for a file (Unix-style), simplify it. For example, path = "/home/", ...
- leetcode 79:simplify path
Given an absolute path for a file (Unix-style), simplify it. For example, path = "/home/", ...
- [LintCode] Simplify Path [字符串操作]
Problem Given an absolute path for a file (Unix-style), simplify it. Example "/home/", =&g ...
- LeetCode Simplify Path(栈操作)
题意:给出一个文件路径,输出简化后的文件路径 如/home/ => /home /.. => / /. => / 思路:当遇到/时,就将字符串压入栈中,同时将字符串清空.在遇到..时 ...
- 继续过中等难度.0309
. 8 String to Integer (atoi) 13.9% Medium . 151 Reverse Words in a String 15.7% Mediu ...
- Leetcode重点250题
LeetCode重点250题 这个重点题目是把LeetCode前400题进行精简.精简方法如下: 删除不常考,面试低频出现题目 删除重复代码题目(例:链表反转206题,代码在234题出现过) 删除过于 ...
- leetcode刷题规划
LeetCode精华题目列表[刷题规划系列] – TuringPlanet 目录 算法题到底在考察什么? 题目列表 Array String Linked List Queue Stack Advan ...
最新文章
- verify https android,信任https
- 卡尔曼滤波的原理说明
- ZOJ3772_Calculate the Function
- web前端技术分享:使用react实现简易路由
- flex 各组件对应的样式属性2
- mac mysql 初始密码_mac下mysql安装后修改默认密码
- 程序随笔——C++实现的一个线程池
- #{}不自动改参数类型_我是干流动补胎的,想让我的柴油机气泵自动打气,怎么改装。谢谢。...
- 求教一个WEBSERVER与C的通信问题
- Android刷Root方法,zergRush,Odin3+CWM(ClockworkMod recovery)
- 分享电脑中截图的五种方法(包括截长图)
- SPSS作业-一元线性回归
- 杀毒软件的一些杀毒原理
- matlab中argmax_argmin(matlab中argmin函数)
- ofbiz UOM Conversion Relationship Not Found [单位转化关系没有找到] 问题解决:
- 如何用c语言对隐函数求导,隐函数求导的方法
- Android攻城狮 Handler与子线程
- vscode绿色、护眼色,vue自动格式化配置参考
- Vmware Workstation Pro 16
- 文件函数python_Python 基础之文件 函数