https://leetcode.com/problems/count-and-say/#/description

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.

Sol:

class Solution(object):
def countAndSay(self, n):
"""
:type n: int
:rtype: str
"""
s=''
for i in range(n-1):
count = 1
temp = []
for index in range(1,len(s)):
if s[index] == s[index-1]:
count += 1
else:
temp.append(str(count))
temp.append(s[index-1])
count = 1
temp.append(str(count))
temp.append(s[-1])
s = ''.join(temp)
return s

TWO SOLUTIONS IN:

https://discuss.leetcode.com/topic/28084/simple-python-solution/4

.join() in python

http://www.cnblogs.com/jsplyy/p/5634640.html

 

38. Count and Say - Unsolved的更多相关文章

  1. LeetCode - 38. Count and Say

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

  2. LeetCode题解38.Count and Say

    38. Count and Say The count-and-say sequence is the sequence of integers beginning as follows: 1, 11 ...

  3. leetCode练题——38. Count and Say

    1.题目 38. Count and Say The count-and-say sequence is the sequence of integers with the first five te ...

  4. 【leetcode❤python】 38. Count and Say

    #-*- coding: UTF-8 -*- class Solution(object):    def countAndSay(self, n):        """ ...

  5. 38. Count and Say

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

  6. 【LeetCode】38 - Count and Say

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

  7. Java [leetcode 38]Count and Say

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

  8. 【一天一道LeetCode】#38. Count and Say

    一天一道LeetCode系列 (一)题目 The count-and-say sequence is the sequence of integers beginning as follows: 1, ...

  9. [leetcode]38. Count and Say数数

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

随机推荐

  1. .net 读取实体属性和描述注释

    .net 读取实体属性和描述注释 class Program { static void Main(string[] args) { TEST test = new TEST(); test.MyNa ...

  2. ArrayList 如何完美去除空值

    package sourceCode.ArrayList; import java.util.ArrayList; import java.util.List; public class arrayL ...

  3. 数据仓库Hive数据导入导出

    Hive库数据导入导出 1.新建表data hive (ebank)> create table data(id int,name string) > ROW FORMAT DELIMIT ...

  4. 进程间通信系列 之 命名管道FIFO及其应用实例

    进程间通信系列 之 概述与对比   http://blog.csdn.net/younger_china/article/details/15808685  进程间通信系列 之 共享内存及其实例   ...

  5. 阿里云CentOS-7.2安装mysql

    我下载的阿里云的服务器系统centos7.2是纯内核版本,并没有其他的工具,所以这个系统是非常干净的.所以我就需要给系统安装一一些工具,来方便系统的管理与操作,我们上面讲到了关于服务器的yum的配置在 ...

  6. 【Java SE】如何用Java实现直接选择排序

    摘要:直接选择排序属于选择排序的一种,但是它的排序算法比冒泡排序的速度要快一些,由于它的算法比较简单,所以也比较适合初学者学习掌握. 适宜人群:有一定Java SE基础,明白Java的数据类型,数组的 ...

  7. Linux 定时任务详解

    原文地址:http://edu.codepub.com/2011/0104/28518.php   crond分为系统级定时和用户级定时,系统级定时主要编辑/etc/crontab,用户级定时主要利用 ...

  8. JavaScript常用的方法和函数(setInterval和setTimeout)

    1.setInterval:计时器 可以按照指定的周期(以毫秒为单位)来调用函数或计算表达式 调用格式:setinterval(fun,time) 说明:fun为函数体,time为数值,这两个参数是必 ...

  9. vue视频学习笔记02

    video 2 vue制作weibo交互 vue-> 1.0vue-resource ajax php服务器环境(node) this.$http.get()/post()/jsonp() th ...

  10. 精准准确的统一社会信用代码正则(js)

    参照标准: <GB_32100-2015_法人和其他组织统一社会信用代码编码规则.> 按照编码规则: 统一代码为18位,统一代码由十八位的数字或大写英文字母(不适用I.O.Z.S.V)组成 ...