leetcode38
public class Solution {
public string CountAndSay(int n) {
//1
//11
//21
//1211
//111221
//312211
//13112221
//1113213211
if (n == )
{
return "";
}
else
{
var list = new List<string>();
list.Add("");
var result = "";
var pre = "";
for (int i = ; i < n; i++)
{
pre = list[i - ];
var c = pre[];
var newrow = new StringBuilder();
var count = ;
for (int j = ; j < pre.Length; j++)
{
var cur = pre[j];
if (c != cur)
{
newrow.Append(count).Append(c);
count = ;
c = cur;
}
else
{
count++;
}
}
newrow.Append(count).Append(c);
list.Add(newrow.ToString());
}
result = list[list.Count - ];
return result;
}
}
}
https://leetcode.com/problems/count-and-say/#/description
leetcode38的更多相关文章
- leetcode-38.报数
leetcode-38.报数 题意 报数序列是一个整数序列,按照其中的整数的顺序进行报数,得到下一个数.其前五项如下: 1. 1 2. 11 3. 21 4. 1211 5. 111221 1 被读作 ...
- LeetCode38 Count and Say
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...
- [Swift]LeetCode38. 报数 | Count and Say
The count-and-say sequence is the sequence of integers with the first five terms as following: 1. 1 ...
- LeetCode38.报数
报数序列是一个整数序列,按照其中的整数的顺序进行报数,得到下一个数.其前五项如下: 1. 1 2. 11 3. 21 4. 1211 5. 111221 1 被读作 "one 1" ...
- Leetcode字符串专题
Leetcode38. Count and Say 分析:根据题意,数列的下一项就是统计上一项中每个数字出现的次数,理解清楚题意就很简单了 class Solution { public: strin ...
- C#刷遍Leetcode面试题系列连载(2): No.38 - 报数
目录 前言 题目描述 相关话题 相似题目 解题思路: 运行结果: 代码要点: 参考资料: 文末彩蛋 前言 前文传送门: C# 刷遍 Leetcode 面试题系列连载(1) - 入门与工具简介 上篇文章 ...
随机推荐
- ubuntu下修改matlab R2016b的快捷键为windows下相同
选为: windows默认类.
- Aizu-2200-floyd+dp
Mr. Rito Post Office 你是一个为远程邮局邮局工作的程序员.你住的地区由几个岛屿组成.每个岛屿都有一个或多个港口城镇.除此之外,还有其他城镇和村庄.为了从一个岛到另一个岛,你必须使用 ...
- 个人知识管理系统Version1.0开发记录(11)
(1)匹配单个属性的关键字:(2)匹配单个对象的关键字:(3)匹配对象集合的关键字:(4)基于事件驱动的:(5)实时搜索,参考win7的搜索功能. 1.备份,java代码,数据库数据. 2.oracl ...
- Xcode6中手动添加Precompile Prefix Header
Xcode5中创建一个工程的时候,系统会自动创建一个以以工程名为名字的pch(Precompile Prefix Header)文件,开发的过程中可以将广泛使用的头文件以及宏包含在该文件下,编译器就会 ...
- PHP和JAVA整合开发的三个方案(六)
php作为前端开发,java负责后台开发,这样取长补短的方案很适合现在web开发.现在PHP和JAVA整合开发比较好的方案只有3个:1.SOAP2.php-java-bridge3.Quercus Q ...
- @pathVariable的作用(二十二)
spring mvc中的@PathVariable是用来获得请求url中的动态参数的,十分方便,复习下: @Controller public class TestController { @Requ ...
- 201621123005《Java程序设计》第十次实验总结
201621123005<Java程序设计>第十周学习总结 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常相关内容. 2. 书面作业 1. 常用异常 1.1 自己 ...
- Unable to connect to any of the specified MySQL hosts.
c#连接Mysql数据建立连接时提示:Unable to connect to any of the specified MySQL hosts. 出现此错误的原因是Server(数据库服务器IP地址 ...
- 如何在未越狱的ios系统安装ipa文件
首先我们先下载一个PP助手正版在电脑上 用iphone打开http://z.25pp.com/?from=bdpz,根据网页上的教程,我们安装好PP助手正版(注意是正版!!) 将手机连接电脑,在电脑上 ...
- ios 加密解密工具类字符判断等
#import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @interface Helpers : NSObject ...