1 Star 1 Fork 0

钦某/Code

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
38.外观数列.cpp 623 Bytes
一键复制 编辑 原始数据 按行查看 历史
钦某 提交于 2025-06-27 00:14 +08:00 . update 模拟算法 leetcode 38 外观数列
/*
* @lc app=leetcode.cn id=38 lang=cpp
*
* [38] 外观数列
*/
// @lc code=start
class Solution
{
public:
string countAndSay(int n)
{
string ret = "1";
for (int j = 0; j < n - 1; j++) // 循环 n - 1 次
{
string tmp;
int l = 0, r = 0;
while (r < ret.size())
{
while (r < ret.size() && ret[r] == ret[l])
++r;
// 解释
tmp += to_string(r - l) + ret[l];
l = r;
}
ret = tmp;
}
return ret;
}
};
// @lc code=end
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/wang-qin928/cpp.git
git@gitee.com:wang-qin928/cpp.git
wang-qin928
cpp
Code
master

搜索帮助