LeetCode #71 Simplify Path (路径化简)

题目:

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

 

分析:

路径化简。

基本思路就是使用栈来模拟进入某一路径或者返回上一级。

注意以下边界情况:

  • "/../" 应化简为 "/"
  • "/home//foo/" 应化简为 "/home/foo"

Continue reading LeetCode #71 Simplify Path (路径化简)