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) - 入门与工具简介 上篇文章 ...
随机推荐
- Hive之GROUP BY详解
一,GROUP BY 执行理解 先来看下表1,表名为test: 表1 执行如下SQL语句: SELECT name from test GROUP BY name ; 你应该很容易知道运行的结果, ...
- ZOJ-3962-数位dp
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5594 16进制下的数位dp,由于固定了位数,可以出现前 ...
- javascript垃圾收集
javascript具有自动垃圾收集机制,也就是说,执行环境会负责管理代码执行过程中使用的内存.而在C和C++之类的语言中,开发人员的一项基本任务就是手工跟踪内存的使用情况 ,这是造成许多问题的一个根 ...
- 简话Angular 00 为什么要学Angular
一句话: 现在不学Angular的结局,就和5年前不学JQuery一样! 谁学谁知道,早学早进阶! 1. JQuery vs Javascipt 问两个问题: 1) 你用过JQuery吗?当然! 2) ...
- Failed to start Docker Application Container
[root@localhost ~]# systemctl status docker.service ● docker.service - Docker Application Container ...
- win10中jdk1.8环境配置完,重启之后配置失效
1.win10操作系统下重启电脑java环境变量失效 解决方式: 右击开始按钮,选择管理员方式的windows powershell,如下图: 在窗口中输入javac,一切正常,即使重启都不会有问题啦 ...
- python3 读入一个jpg格式的图片,并转换长宽像素个数,然后进行绘制
import matplotlib.pyplot as plt from scipy import ndimage import numpy as np import scipy fname=&quo ...
- Mac Book Pro重新安装出错
错误描述 未能创建用于apfs安装的预启动宗卷 解决 网上的经验: 返场重修 多试几次拼人品 多试了几次之后还是没用,选择U盘安装. 搞定! U盘安装教程
- Windows7 SP1 64bit配置IIS7.5和ASP.NET4
一.安装前的环境 1. Windows7 SP1 64bit: 2. 在安装IIS7.5之前,安装了Visual Studio 2010或.NET Framework4: 二.安装IIS7.5 1. ...
- USB gadget学习笔记
1.usb-OTG-ADP-HNP-SRP https://blog.csdn.net/xiongjiao0610/article/details/44150849