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的更多相关文章

  1. leetcode-38.报数

    leetcode-38.报数 题意 报数序列是一个整数序列,按照其中的整数的顺序进行报数,得到下一个数.其前五项如下: 1. 1 2. 11 3. 21 4. 1211 5. 111221 1 被读作 ...

  2. LeetCode38 Count and Say

    The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...

  3. [Swift]LeetCode38. 报数 | Count and Say

    The count-and-say sequence is the sequence of integers with the first five terms as following: 1. 1 ...

  4. LeetCode38.报数

    报数序列是一个整数序列,按照其中的整数的顺序进行报数,得到下一个数.其前五项如下: 1. 1 2. 11 3. 21 4. 1211 5. 111221 1 被读作  "one 1" ...

  5. Leetcode字符串专题

    Leetcode38. Count and Say 分析:根据题意,数列的下一项就是统计上一项中每个数字出现的次数,理解清楚题意就很简单了 class Solution { public: strin ...

  6. C#刷遍Leetcode面试题系列连载(2): No.38 - 报数

    目录 前言 题目描述 相关话题 相似题目 解题思路: 运行结果: 代码要点: 参考资料: 文末彩蛋 前言 前文传送门: C# 刷遍 Leetcode 面试题系列连载(1) - 入门与工具简介 上篇文章 ...

随机推荐

  1. java.lang.NoSuchMethodError: org.springframework.core.io.ResourceEditor

    这种情况一般是jar包版本问题,pom导入的jar包存在一个2.5.6的,删掉即可.

  2. [linux]文件系统损坏,linux启动时 checking filesystems fail

    先敲root password进入maintenance状态,然后fsck -y /dev/mapper/vg_wwwdata-lv_root等干净了以后,再exit就行了. ------------ ...

  3. 如果从excel表中导出insert-sql

    =CONCATENATE("INSERT INTO p_act_lottery(actId,status,grantWay,createTime,invalidTime,amount,pri ...

  4. SVN 提交代码时强制加入注释内容

    参考: 关于SVN提交强制加入注释 方式一是使用的服务器脚本,对所有SVN用户生效. 方式二是使用本地钩子,仅对当前SVN用户生效.

  5. python 读写西门子PLC 包含S7协议和Fetch/Write协议,s7支持200smart,300PLC,1200PLC,1500PLC

    本文将使用一个gitHub开源的组件技术来读写西门子plc数据,使用的是基于以太网的TCP/IP实现,不需要额外的组件,读取操作只要放到后台线程就不会卡死线程,本组件支持超级方便的高性能读写操作 nu ...

  6. java - 百钱百鸡小算法

    传送门: 袁咩咩的小小博客 百钱百鸡是一个非常经典的不定方程问题,最早源于我国古代的<算经>,这是古代著名数学家张丘建首次提出的.百钱百鸡问题原文如下: 鸡翁一,值钱五,鸡母一,值钱三,鸡 ...

  7. zoj 1828 Fibonacci Numbers

    A Fibonacci sequence is calculated by adding the previous two members of the sequence, with the firs ...

  8. .NET4.0中使用4.5中的 async/await 功能实现异步

    在.NET Framework 4.5中添加了新的异步操作库,但是在.NET Framework 4.0中却无法使用.这时不免面临着抉择,到底是升级整个解决方案还是不使用呢? 如果你的软件还没发布出去 ...

  9. ambassador 学习九 多ambassador部署说明

    目前官方稳文档没有写,但是demo 里面有,所以就整理出来,其实目前demo里面的 多实例部署用了多个服务的service(使用nodeport 暴露地址,具体使用就是制定ambassador 实例的 ...

  10. CentOS7 tomcat systemctl脚本

    1,centos7 使用 systemctl 替换了 service命令 参考:redhat文档: https://access.redhat.com/documentation/en-US/Red_ ...