[leetcode]Simplify Path
来源:互联网 发布:淘宝直播如何找商家 编辑:程序博客网 时间:2024/04/29 04:00
class Solution {public: string simplifyPath(string path) { // Start typing your C/C++ solution below // DO NOT write int main() function if(path.empty()) return ""; if(path[path.size()-1] != '/') path += "/"; int N = path.size(); stack<string> s; string tmp; for(int i = 0; i < N; i++){ if(path[i] == '/'){ if(tmp == ".."){ if(!s.empty()) s.pop(); }else if(!tmp.empty() && tmp != "." && tmp != ".."){ s.push(tmp); } tmp.clear(); }else{ tmp += path[i]; } } //reverse stack stack<string> s1; while(!s.empty()){ s1.push(s.top()); s.pop(); } string result = ""; while(!s1.empty()){ result += "/"; result += s1.top(); s1.pop(); } return result == "" ? "/" : result; }};
- LeetCode: Simplify Path
- LeetCode Simplify Path
- LeetCode : Simplify Path
- [Leetcode] Simplify Path
- [leetcode] simplify path
- [LeetCode] Simplify Path
- leetcode 100: Simplify Path
- [leetcode]Simplify Path
- [LeetCode]Simplify Path
- [leetCode] Simplify Path
- [leetcode]Simplify Path
- [leetcode] Simplify Path
- [LeetCode] Simplify Path
- leetcode simplify path
- Leetcode: Simplify Path
- LeetCode题解:Simplify Path
- [LeetCode] Simplify Path
- LeetCode Simplify Path
- 关于OnOK()、OnCancel()、OnClose()、OnDestroy() 模式对话框
- 10 Tips for Learning a New Technology
- android-数字提醒
- js xml 简单的城市联动
- 收缩SqlServer 2008数据库日志
- [leetcode]Simplify Path
- Useful Linux Wireless Commands
- uva 10055 Hashmat the brave warrior
- vibrato
- centos6 Linux安装redis 2.6.14
- poj 1573 Robot Motion_模拟
- C基础笔记1
- 从sqlite获取的数据空字符串的判断方式
- SUSE Linux 10 配置裸设备(raw devices)