博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LeetCode – Refresh – Count and Say
阅读量:7072 次
发布时间:2019-06-28

本文共 759 字,大约阅读时间需要 2 分钟。

Pretty straight forward. count numbers and put char.

1 class Solution { 2 public: 3     string getNext(string s) { 4         ostringstream oss; 5         char rec = s[0]; 6         int len = s.size(), num = 1; 7         for (int i = 1; i < len; i++) { 8             if (rec != s[i]) { 9                 oss << char(num + '0') << rec;10                 rec = s[i];11                 num = 1;12             } else num++;13         }14         oss << char(num + '0') << rec;15         return oss.str();16     }17     string countAndSay(int n) {18         string result = "1";19         for (int i = 2; i <= n; i++) {20             result = getNext(result);21         }22         return result;23     }24 };

 

转载于:https://www.cnblogs.com/shuashuashua/p/4349360.html

你可能感兴趣的文章
Redis 深入
查看>>
Windows API 第三篇
查看>>
小组绩效考核
查看>>
es集群数据库~基本安装
查看>>
树链剖分+线段树 BZOJ 1036 [ZJOI2008]树的统计Count
查看>>
Node知识总结
查看>>
MYSQL 基于GTID的复制
查看>>
ASP.NET Core 找不到 npm指令异常
查看>>
http://python3-cookbook.readthedocs.io/zh_CN/latest/c14/p01_testing_output_sent_to_stdout.html
查看>>
.net分页方法
查看>>
UI方法调用顺序和UI常用操作
查看>>
array_map
查看>>
汽水瓶
查看>>
我的ACM技能框架(自用)
查看>>
Signalr系列之虚拟目录详解与应用中的CDN加速实战
查看>>
程序员基本素养
查看>>
scala(5)-----访问修饰符
查看>>
大黄扫毒汤的学习
查看>>
回调的经典理解
查看>>
时间戳转换
查看>>