LeetCode之Simplify Path
2015-07-07 17:32
405 查看
/*细节模拟题。 参考自:https://github.com/soulmachine/leetcode*/ class Solution { public: string simplifyPath(string path) { string res; vector<string> path_name; string::iterator it = path.begin(); while(it != path.end()){ ++it; string::iterator itt = find(it, path.end(), '/'); string dir(it, itt); if(!dir.empty() && dir != "."){//dir为有效目录 if(dir == ".."){//返回上级目录 if(!path_name.empty()) path_name.pop_back(); } else{ path_name.push_back(dir); } } it = itt; } if(path_name.empty()) return "/"; for(int i = 0; i < path_name.size(); ++i) res = res + "/" + path_name[i]; return res; } };
相关文章推荐
- iOS-ui-UISlider
- meteor中分页库alethes:pages用法汇总
- C# snaps
- 我的Android进阶之旅------>Android中ListView中嵌套(ListView)控件时item的点击事件不起作的问题解决方法
- debian_用iso文件创建本地apt源
- haproxy 页面重定向(域名跳转)
- C#自动更新
- XSD (xml Schema Definition)
- 基于注解的SpringMVC简单介绍
- iOS 本地推送 UILocalNotification
- C语言实现顺序栈的基本操作(初始化、判断空、入栈、出栈、获取栈顶元素)
- 进程调度
- 2.13 带逗号的print语句输出的元素之间自动带个空格
- lua函数随记
- Android通讯录获取联系方式
- UIAlertView/警告框
- GBK编码详细解析(附GBK码位分布图)
- 淘宝TFS分布式文件系统内部实现
- android实现wifi与移动数据的切换
- nginx配置