71. Simplify Path

 Given an absolute path for a file (Unix-style), simplify it.

 For example,
path = "/home/", => "/home"
path = "/a/./b/../../c/", => "/c"
click to show corner cases. Corner Cases:
Did you consider the case where path = "/../"?
In this case, you should return "/".
Another corner case is the path might contain multiple slashes '/' together, such as "/home//foo/".
In this case, you should ignore redundant slashes and return "/home/foo".
 class Solution {
public:
string simplifyPath(string path) {
deque<string> qs;
string result;
int plen = path.size();
string::size_type curindex = , lastindex = ; while (lastindex < plen && (curindex = path.find("/", lastindex)) != string::npos)
{
if(path.find("//", lastindex))
{
qs.push_back(path.substr(lastindex, curindex+-lastindex));
lastindex = curindex+;
}else if (path.find("./", lastindex)) {
lastindex = curindex+;
}else if (path.find(".//", lastindex)) {
lastindex = curindex+;
}else if (path.find("../", lastindex)) {
qs.pop_back(); // go back one step
lastindex = curindex+;
}else if (path.find("..//", lastindex)) {
qs.pop_back();
lastindex = curindex+;
}else {
qs.push_back(path.substr(lastindex, curindex+-lastindex));
lastindex = curindex+;
}
} while (!qs.empty()) {
string tmp = qs.front();
qs.pop_front();
result.append(tmp);
}
if(result.size() != ){
result.resize(result.size()-);
}
return result;
}
};

71. Simplify Path(M)的更多相关文章

  1. 【LeetCode】71. Simplify Path 解题报告(Python)

    [LeetCode]71. Simplify Path 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://f ...

  2. 【LeetCode】71. Simplify Path

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

  3. 71. Simplify Path

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

  4. 【一天一道LeetCode】#71. Simplify Path

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...

  5. 71. Simplify Path (Stack)

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

  6. 71. Simplify Path压缩文件的绝对路径

    [抄题]: Given an absolute path for a file (Unix-style), simplify it. For example,path = "/home/&q ...

  7. [LeetCode] 71. Simplify Path 简化路径

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

  8. [LC] 71. Simplify Path

    Given an absolute path for a file (Unix-style), simplify it. Or in other words, convert it to the ca ...

  9. Leetcode#71 Simplify Path

    原题地址 用栈保存化简后的路径.把原始路径根据"/"切分成若干小段,然后依次遍历 若当前小段是"..",弹栈 若当前小段是".",什么也不做 ...

随机推荐

  1. Git中使用amend解决提交冲突

    问题描述       场景:当你提交的时候,发现跟要合并的流有冲突,你需要解决完冲突再次提交. 如果在SVN时代,你可以直接在本地解决完冲突再提交就可以了,因为SVN会把正确的代码先提交到服务器,至于 ...

  2. 对*P++的理解,再联想~~~

    前言: 最近在看一位叫朱有鹏大神的视频,讲的甚好.应此,我的感悟也因此被激发,准备针对朱老师将的内容,结合自己的理解,写一个系列的笔记博客--大家可以去www.zhulaoshi.org观看视频-- ...

  3. 【php增删改查实例】第四节 -自己 DIY 一个数据库管理工具

    本节介绍如何自己DIY一个数据库管理工具,可以在页面输入sql 进行简单的增删改查操作. 首先,找到xampp的安装目录,打开htdocs: 新建一个php文件,名称为 mysqladmin.php ...

  4. TMS320VC5509使用nof flash AM29LV400

    1. 硬件接口如下,其中nor flash的使用方法,写的时候和NAND FLASH是一样的,读的时候和DRAM是一样的 2. 看下擦除指令和编程指令 3. 代码如下 #include <csl ...

  5. opencv配置(转)

    1. 下载安装Opencv,去官网http://opencv.org/即可下载最新版本的Opencv,此处用的是Opencv 2.4.10 安装时傻瓜式的,最新版本的安装就是相当于解压到你指定的安装目 ...

  6. libgdx学习记录1——图片显示Texture

    libgdx底层采用opengl渲染,对图片进行了优化处理,与android原生态的bitmap不太一样. 相比而言,效率要高一些,不过只支持png,jpg,bmp三种格式. 显示中,一般将图片放在a ...

  7. 在Windows上安装配置Git

    用安装 https://git-scm.com/ 官网下载安装包 (官网有安装步骤 https://git-scm.com/book/zh/v1/%E8%B5%B7%E6%AD%A5-%E5%AE%8 ...

  8. Unity角色对话

    对话类------------------------------------------------------------------------------------------------- ...

  9. ES6实用新特性

    兼容性 http://kangax.github.io/compat-table/es5/ http://kangax.github.io/compat-table/es6/ ES6(ES2015)兼 ...

  10. javascript 函数的几种声明函数以及应用环境

    本页只列出常用的几种方式,当然还有比如new Function()以及下面三种的组合. 1.函数式声明 例子:function sum(a,b){ return a+b; }; 2.函数表达式声明(匿 ...