Leetcode 之Simplify Path(36)
2024-08-27 20:24:14
主要看//之间的内容:如果是仍是/,或者是.,则忽略;如果是..,则弹出;否则压入堆栈。最后根据堆栈的内容进行输出。
string simplifyPath(string const& path)
{
vector<string> dirs;
for (auto i = path.begin(); i != path.end();)
{
i++;
auto j = find(i, path.end(), '/');
auto dir = string(i, j);//注意用法 if (!dir.empty() && dir != ".")//当有连续的///时dir为空
{
if (dir == "..")
{
if (!dirs.empty())
dirs.pop_back();
}
else
dirs.push_back(dir);
}
i = j;
} stringstream out;
if (dirs.empty())
{
out << "/";
}
else
{
for (auto dir : dirs)
{
out << '/' << dir;
}
} return out.str();
}
最新文章
- mongodb数据库迁移
- canvas实现绘画
- angular的directive笔记
- [wordpress] 输出一个过滤器绑定的方法
- 添加“返回顶部”小图标按钮的JS(JavaScript)代码详解
- IIS服务器 远程发布(Web Deploy)配置 VS2010 开发环境 Windows Server 2008服务器系统
- “字符串替换” 和 “模板设置” (application/config.php)
- node.js的安装的配置
- SpringBoot的第一个例子
- Oracle debug
- 学习animejs
- Delphi 10.3.1来了
- spring模拟ioc
- FPGA学习笔记. 二分频和三分频
- Windows平台编译SQLite 3
- CodeForces 76A Gift - 最小生成树
- npm 下载node-zookeeper包
- JS之this那些事
- ruby require的使用
- 指定Python线程数目
热门文章
- BZOJ5217:[Lydsy2017省队十连测]航海舰队——题解
- BZOJ4651 &; 洛谷1173 &; UOJ220:[NOI2016]网格——题解(附debug数据)
- Python通过PhantomJS获取JS渲染后的网页源代码
- 总结:Bias(偏差),Error(误差),Variance(方差)及CV(交叉验证)
- ubuntu14.04安装GTX 1080 ti遇到黑屏问题
- UVA315:Network(求割点)
- Java的switch是否支持String作为参数,还支持哪些类型?
- jQuery图表插件Flot中文文档
- 【C++ STL】Deques
- 【C++对象模型】第五章 构造、解构、拷贝 语意学