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. 基于Boost库的HTTP Post函数

    两个函数的区别: 提交表单数据和提交文本数据 表单数据: request_stream << "Content-Type: application/x-www-form-urle ...

  2. idea 项目java版本选项位置

    藏这里了 还有一个

  3. 移动端页面滑动时候警告:Unable to preventDefault inside passive event listener due to target being treated as passive.

    移动端项目中,在滚动的时候,会报出以下提示: [Intervention] Unable to preventDefault inside passive event listener due to ...

  4. LOJ#6503.「雅礼集训 2018 Day4」Magic[容斥+NTT+启发式合并]

    题意 \(n\) 张卡牌 \(m\) 种颜色,询问有多少种本质不同的序列满足相邻颜色相同的位置数量等于 \(k\). 分析 首先本质不同不好直接处理,可以将同种颜色的卡牌看作是不相同的,求出答案后除以 ...

  5. falsk之文件上传

    在使用flask定义路由完成文件上传时,定义upload视图函数 from flask import Flask, render_template from werkzeug.utils import ...

  6. 异步编程之asyncio简单介绍

    引言: python由于GIL(全局锁)的存在,不能发挥多核的优势,其性能一直饱受诟病.然而在IO密集型的网络编程里,异步处理比同步处理能提升成百上千倍的效率,弥补了python性能方面的短板. as ...

  7. 在Windows上安装配置Git

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

  8. Estimation And Gain

    Estimation: Almost every is spent on ergod the text and build the dictionary. Gains: I have never us ...

  9. C#获取每月最后一天或者最末一天的方法

    /// <summary> /// 取得某月的第一天 /// </summary> /// <param name="datetime">要取得 ...

  10. C++ Makefile文件编写

    对现有的一个C++动态库文件和调用程序,分别编写Makefile文件,从零开始,这里把自己弄明白的一些东西分享给大家. 1.必须明确Linux下,C++的编译器是g++,C语言的是gcc.网上大多数又 ...