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相关推荐

  1. LeetCode 71. Simplify Path

    LeetCode 71. Simplify Path 本博客转载自:https://blog.csdn.net/makuiyu/article/details/44497901 Solution1:没 ...

  2. [LeetCode]--71. Simplify Path

    Given an absolute path for a file (Unix-style), simplify it. For example, path = "/home/", ...

  3. [Leetcode] Simplify Path

    Given an absolute path for a file (Unix-style), simplify it. For example, path = "/home/", ...

  4. leetcode 79:simplify path

    Given an absolute path for a file (Unix-style), simplify it. For example, path = "/home/", ...

  5. [LintCode] Simplify Path [字符串操作]

    Problem Given an absolute path for a file (Unix-style), simplify it. Example "/home/", =&g ...

  6. LeetCode Simplify Path(栈操作)

    题意:给出一个文件路径,输出简化后的文件路径 如/home/ => /home /.. => / /. => / 思路:当遇到/时,就将字符串压入栈中,同时将字符串清空.在遇到..时 ...

  7. 继续过中等难度.0309

      .   8  String to Integer (atoi)    13.9% Medium   . 151 Reverse Words in a String      15.7% Mediu ...

  8. Leetcode重点250题

    LeetCode重点250题 这个重点题目是把LeetCode前400题进行精简.精简方法如下: 删除不常考,面试低频出现题目 删除重复代码题目(例:链表反转206题,代码在234题出现过) 删除过于 ...

  9. leetcode刷题规划

    LeetCode精华题目列表[刷题规划系列] – TuringPlanet 目录 算法题到底在考察什么? 题目列表 Array String Linked List Queue Stack Advan ...

最新文章

  1. verify https android,信任https
  2. 卡尔曼滤波的原理说明
  3. ZOJ3772_Calculate the Function
  4. web前端技术分享:使用react实现简易路由
  5. flex 各组件对应的样式属性2
  6. mac mysql 初始密码_mac下mysql安装后修改默认密码
  7. 程序随笔——C++实现的一个线程池
  8. #{}不自动改参数类型_我是干流动补胎的,想让我的柴油机气泵自动打气,怎么改装。谢谢。...
  9. 求教一个WEBSERVER与C的通信问题
  10. Android刷Root方法,zergRush,Odin3+CWM(ClockworkMod recovery)
  11. 分享电脑中截图的五种方法(包括截长图)
  12. SPSS作业-一元线性回归
  13. 杀毒软件的一些杀毒原理
  14. matlab中argmax_argmin(matlab中argmin函数)
  15. ofbiz UOM Conversion Relationship Not Found [单位转化关系没有找到] 问题解决:
  16. 如何用c语言对隐函数求导,隐函数求导的方法
  17. Android攻城狮 Handler与子线程
  18. vscode绿色、护眼色,vue自动格式化配置参考
  19. Vmware Workstation Pro 16
  20. 文件函数python_Python 基础之文件 函数

热门文章

  1. 博客园首页新随笔联系管理订阅订阅随笔- 610 文章- 0 评论- 83 阅读- 144万 Calendar时间获取天,周,月,季度,年度时间段
  2. MYSQL索引创建与删除
  3. Kotlin入门(31)JSON字符串的解析
  4. 《游戏大师Chris Crawford谈互动叙事》一1.1 故事叙述的历史
  5. react-redux学习笔记
  6. nginx的高级配置(1)——为某个虚拟主机添加用户验证
  7. 人人都是产品经理 笔记
  8. 20个使用柔和的色调的优秀网站设计示例
  9. PXE无人值守系统安装配置简要说明
  10. CCNA学习指南十三章