2018秋招 搜狐 简化路径
来源:互联网 发布:微信配图软件 编辑:程序博客网 时间:2024/05/17 00:57
这题是leetcode原题
Given an absolute path for a file (Unix-style), simplify it.
For example,
path = “/home/”, => “/home”
path = “/a/./b/../../c/”, => “/c”
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”.
AC代码:
class Solution {public: string simplifyPath(string path) { string res, tmp; vector<string> stk; stringstream ss(path); while (getline(ss, tmp, '/')) { if (tmp == "" or tmp == ".") continue; if (tmp == ".." && !stk.empty()) stk.pop_back(); else if (tmp != "..") stk.push_back(tmp); } for (auto str : stk) res += "/" + str; return res.empty() ? "/" : res; }};
阅读全文
0 0
- 2018秋招 搜狐 简化路径
- 2018秋招 搜狐 回文数组
- 搜狐2017笔试题----Unix路径简化
- 搜狐 2017秋招研发
- 2018搜狐秋招 Kolakoski生成序列问题答案
- 2018搜狐秋招笔试题2 最少包裹数
- 搜狐2018研发工程师秋招笔试题
- 搜狐笔试题——Unix简化路径
- 搜狐2017秋招编程题
- 搜狐2018校招笔试题
- 2018搜狐秋招笔试_Kolakoski序列_C++_部分回忆版Demo
- 搜狐2017秋招研发工程师笔试题目
- 搜狐2017 WEB前端开发 秋招笔试编程题
- 搜狐集团2018秋季校招笔试题 kolakoski序列
- 搜狐集团2018秋季校招笔试题 包裹问题
- 搜狐校招笔试题
- 简化路径
- 简化路径
- 《C和指针》读书笔记(一)
- 好朋友的工具合集
- SSM_mybatis入门学习总结
- [Git] 使用....
- Win10下MySQL_Workbench连接远程主机MySQL5.7
- 2018秋招 搜狐 简化路径
- UIScrollView的总结
- vue 三目运算
- 程序媛:数据库操作(sqlite3)
- Java300StudyNote(2)反射-常用泛型操作(参数泛型、返回值泛型)
- zookeeper总结
- java 基础知识总结
- 题1
- 学习计算机视觉资源