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. 汇编 (NOT)按位取反指令

    知识点:  (NOT)按位取反指令  逻辑取反(!)  按位取反(~)  SETZ(SETE) 取ZF位值保存  SETNZ(SETNE)将ZF位值取反后保存 一.逻辑取反(!) !111 ...

  2. 蓝牙inquiry流程之命令下发

    Android 上面的蓝牙inquiry 是在设置界面,打开蓝牙就会自动搜索周边的蓝牙设备,其最终调用到协议栈的start_discovery接口,此篇文章分析该接口的调用流程以及与controlle ...

  3. PowerBI开发 第一篇:设计PowerBI报表

    PowerBI是微软新一代的交互式报表工具,把相关的静态数据转换为酷炫的可视化的,能够根据filter条件,对数据执行动态筛选,从不同的角度和粒度上分析数据.PowerBI主要由两部分组成:Power ...

  4. 利用fiddler core api 拦截修改 websocket 数据

    一般的中间人攻击基本都是拦截修改普通的http协议里面的内容,而对于怎么拦截修改websocket协议传输的内容好像都没有多少介绍. talk is cheap show me the code us ...

  5. .NET Core容器化开发系列(一)——Docker里面跑个.NET Core

    前言 博客园中已经有很多如何在Docker里面运行ASP.NET Core的介绍了.本篇主要介绍一些细节,帮助初学的朋友更加深入地理解如何在Docker中运行ASP.NET Core. 安装Docke ...

  6. Js_增删改Cookie的值

    //获得cookie 的值function cookie(name) { var cookieArray = document.cookie.split("; "); //得到分割 ...

  7. 读取配置文件的URL,使用httpClient发送Post和Get请求,实现查询快递物流和智能机器人对话

    1.主要jar包: httpclient-4.3.5.jar   httpcore-4.3.2.jar 2.目录结构如图所示: 3.url.properties文件如下: geturl=http:// ...

  8. IDEA2018.1安装配置文档

    一.软件安装 1. 下载地址: https://www.jetbrains.com/idea/download/#section=windows 2. 安装: 点击.exe,选择安装路径,点击next ...

  9. JAVA每日一旅2

    1.关于类型转换 两个数值进行二元操作时,会有如下的转换操作: 如果两个操作数其中有一个是double类型,另一个操作就会转换为double类型. 否则,如果其中一个操作数是float类型,另一个将会 ...

  10. Spring学习总结之高级装配

    1.  profile profile可以决定bean在什么环境下才被装配(开发环境.测试环境.线上环境等) @Profile(“dev”)可以用在class之前,也可以用在类之前(Spring3.2 ...