LeetCode *** 71. Simplify Path (getline的使用)
来源:互联网 发布:teamviewer linux 使用 编辑:程序博客网 时间:2024/05/22 12:34
题目:
Given an absolute path for a file (Unix-style), simplify it.
For example,
path = "/home/"
, => "/home"
path = "/a/./b/../../c/"
, => "/c"
分析:
代码:
class Solution {public: string simplifyPath(string path) { string res="", tmp; vector<string> stk; stringstream sstm(path); while(getline(sstm,tmp,'/')){ if(tmp==""||tmp==".")continue; if(tmp==".."&&!stk.empty())stk.pop_back(); else if(tmp!="..")stk.push_back(tmp); } for(auto st:stk)res+="/"+st; return res.empty()?"/":res; }};
0 0
- LeetCode *** 71. Simplify Path (getline的使用)
- LeetCode 71. Simplify Path
- LeetCode --- 71. Simplify Path
- [Leetcode] 71. Simplify Path
- [leetcode] 71.Simplify Path
- [leetcode] 71.Simplify Path
- Leetcode 71. Simplify Path
- LeetCode 71. Simplify Path
- Leetcode 71. Simplify Path
- 71. Simplify Path LeetCode
- leetcode 71. Simplify Path
- LeetCode 71. Simplify Path
- LeetCode 71. Simplify Path
- Leetcode 71. Simplify Path
- [leetcode] 71. Simplify Path
- LeetCode 71. Simplify Path
- LeetCode - 71. Simplify Path
- [LeetCode] 71. Simplify Path
- Android 针对个人开发者的bmob支付
- nodejs完整登陆交互
- 几大最短路径算法比较(Floyd & Dijkstra & Bellman-Ford & SPFA)
- Android Studio更换现名图片导致编译失败
- address code pre ul-li div table
- LeetCode *** 71. Simplify Path (getline的使用)
- C枚举类型小结
- 2015年终总结 更大的变化
- 堆和栈的区别
- Sublime Text3常用快捷键
- poj 3080 Blue Jeans 【kmp+暴力】
- UVa 10815 - Andy's First Dictionary
- Oracle--单行函数
- Eclipse中创建Maven多模块工程