38. Count and Say

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

1 is read off as "one 1" or 11.
11 is read off as "two 1s" or 21.
21 is read off as "one 2, then one 1" or 1211.

Given an integer n, generate the nth sequence.

Note: The sequence of integers will be represented as a string.

说真的刚开始真不知道这道题要干什么,英语有点差~~~

当明白是什么意思的时候又发现描述起来有点问题,语文有点差~~~

生硬的描述一下吧:1被读作“1个1” 或  11;11被读作“2个1”或21;21被读作“1个2,1个1”或1211;依次这样下去,输出第n个序列。

代码如下:

 class Solution {
public:
string countAndSay(int n) {
string first = "";
for(int i = ; i < n; i++)
{
string ss = "";
int count = ;
for(int j = ; j < first.length(); j++)
{
if(first[j-] == first[j])
{
count ++;
}
else
{
ss = ss + (char)(count + '') + first[j-];
count = ;
}
}
first = ss + (char)(count + '') + first[first.length()-];
}
return first;
}
};

leetcode 38的更多相关文章

  1. [LeetCode] 38. Count and Say 计数和读法

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

  2. Java实现 LeetCode 38 外观数列

    38. 外观数列 「外观数列」是一个整数序列,从数字 1 开始,序列中的每一项都是对前一项的描述.前五项如下: 1 11 21 1211 111221 1 被读作 "one 1" ...

  3. LeetCode - 38. Count and Say

    38. Count and Say Problem's Link ------------------------------------------------------------------- ...

  4. LeetCode 38 Count and Say(字符串规律输出)

    题目链接:https://leetcode.com/problems/count-and-say/?tab=Description   1—>11—>21—>1211—>111 ...

  5. LeetCode(38)题解: Count and Say

    https://leetcode.com/problems/count-and-say/ 题目: The count-and-say sequence is the sequence of integ ...

  6. Leetcode 38.报数 By Python

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

  7. [leetcode] 38. 报数(Java)(字符串处理)

    38. 报数 水题 class Solution { public String next(String num) { String ans = ""; int i = 0; wh ...

  8. Leetcode 38 Count and Say 传说中的递推

    class Solution { public: vector<string> vs_; Solution(){ "); vs_.push_back(t); ; i< ;+ ...

  9. leetcode 38 Count and Say ---java

    这道题主要就是求一个序列,题目得意思就是 1 --> 11 --> 21 --> 1211 -->   111221 --> 312211 --> ..... 1个 ...

随机推荐

  1. Transact-SQL的除法问题

    SELECT 3800/365, 3800.0/365; 执行上面的sql,得到的结果是:10, 10.410958 返回优先级较高的参数的数据类型. 有关详细信息,请参阅数据类型优先级 (Trans ...

  2. php表单数据验证类

    非常好用方便的表单数据验证类 <?php //验证类 class Fun{ function isEmpty($val) { if (!is_string($val)) return false ...

  3. Gerrit清单库配置(转载)

    From:http://fatalove.iteye.com/blog/1340334 gerrit清单库是用来配合repo使用的.清单库中列出了gerrit服务器上的其他版本库. 客户端通过repo ...

  4. SIT和UAT的区别

    SIT和UAT有什么区别?谢谢! 系统内部集成测试(System   Integration   Testing) SIT 用户验收测试(User   Acceptance Testing) UAT ...

  5. 慎用StringEscapeUtils.escapeHtml方法【转】

    推荐使用Apache commons-lang的StringUtils来增强Java字符串处理功能,也一直在项目中大量使用StringUtils和StringEscapeUtils这两个实用类. 最近 ...

  6. [ActionScript 3.0] AS3 深入理解Flash的 应用程序域Application Domains

    简介 网上有很多flash,通常都不需要显示的使用应用程序域,因为默认的应用程序域就够用了.其实复杂的情况下需要用到应用程序域,比如说有两个不同的swf,一个是旧版本的,一个是新版的,这两个文件里的类 ...

  7. Understanding Python metaclasses

    转载:https://blog.ionelmc.ro/2015/02/09/understanding-python-metaclasses/ None of the existing article ...

  8. List<IPoint> to IPointCollection to IPolygon

    IPointCollection 到 IPolygon的转换 IPoint pPoint = new PointClass();            //IPolygon pPolygon1 = n ...

  9. [DataTable]C# datatable取最大值最小值

    ArrayList al = new ArrayList(); DataTable dt = new DataTable(); dt.Columns.Add("A",typeof( ...

  10. 剑指offer习题集

    1.重载赋值运算符函数:(具体见代码) //普通做法 CMyString& CMyString::operator=(const CMyString& str) { if (this ...