class Solution(object):
def countAndSay(self, n):
"""
:type n: int
:rtype: str
"""
s=''
for i in range(2,n+1):
s=self.count(s)
return s
def count(self,s):
t='';count=0;curr='#'
for i in s:
if i != curr:
if curr != '#':
t+=str(count)+curr
curr=i
count=1
else:
count+=1
t+=str(count)+curr
return t

@link http://www.cnblogs.com/zuoyuan/p/3781329.html

leetcode Count and Say python的更多相关文章

  1. LeetCode初级算法的Python实现--排序和搜索、设计问题、数学及其他

    LeetCode初级算法的Python实现--排序和搜索.设计问题.数学及其他 1.排序和搜索 class Solution(object): # 合并两个有序数组 def merge(self, n ...

  2. LeetCode初级算法的Python实现--字符串

    LeetCode初级算法的Python实现--字符串 # 反转字符串 def reverseString(s): return s[::-1] # 颠倒数字 def reverse(x): if x ...

  3. LeetCode初级算法的Python实现--数组

    LeetCode初级算法的Python实现--数组 # -*- coding: utf-8 -*- """ @Created on 2018/6/3 17:06 @aut ...

  4. [leetcode]Word Ladder II @ Python

    [leetcode]Word Ladder II @ Python 原题地址:http://oj.leetcode.com/problems/word-ladder-ii/ 参考文献:http://b ...

  5. LeetCode初级算法的Python实现--链表

    LeetCode初级算法的Python实现--链表 之前没有接触过Python编写的链表,所以这里记录一下思路.这里前面的代码是和leetcode中的一样,因为做题需要调用,所以下面会给出. 首先定义 ...

  6. 【数据结构】Hash表简介及leetcode两数之和python实现

    文章目录 Hash表简介 基本思想 建立步骤 问题 Hash表实现 Hash函数构造 冲突处理方法 leetcode两数之和python实现 题目描述 基于Hash思想的实现 Hash表简介 基本思想 ...

  7. leetcode:Count and Say【Python版】

    一次AC 字符串就是:count+char class Solution: # @return a string def countAndSay(self, n): str = " for ...

  8. [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

  9. [LeetCode] Count of Range Sum 区间和计数

    Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Ra ...

随机推荐

  1. 【LeetCode】【Python】Linked List Cycle

    Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using ex ...

  2. 月赛-Crackhash

    Crackhash 这个题目是我为月赛出的,完全仿照自mma 1st simple_hash. 这道题目比较有意思的地方在于在32位的程序中模拟了64位的算术运算. 题目的思路很清晰.要求输入全为数字 ...

  3. js实现form表单提交,图片预览功能

    代码如下 <html> <head> <meta http-equiv="Content-Type" content="text/html; ...

  4. 操作Sql数据库帮助类

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...

  5. javascript的几种时间格式

    1.当前系统区域设置格式(toLocaleDateString和toLocaleTimeString) 例子:(new Date()).toLocaleDateString() + " &q ...

  6. SQL常用日期函数

    原文:http://www.cnblogs.com/coconut_zhang/archive/2009/02/02/1382598.html 1. 当前系统日期.时间 select getdate( ...

  7. T-sql编程

    T-Sql中的变量都是@符号开头的 以一个@符号开头,叫做“用户声明的变量” 以两个@@开头的叫做"全局变量","系统变量",是由系统来维护的.无需我们维护 - ...

  8. js 完美兼容浏览器的复制功能

    1,js结合swf的复制功能,完美兼容火狐,谷歌,360,ie8,使用示例:(ps:引入copy.swf比较重要,文件传送门 解压密码:http://www.bieanju.com/,为了防止360删 ...

  9. 【转】Perl Unicode全攻略

    Perl Unicode全攻略 耐心看完本文,相信你今后在unicode处理上不会再有什么问题. 本文内容适用于perl 5.8及其以上版本. perl internal form 在Perl看来, ...

  10. xml drawable

    1.Shape drawable:改变组件的形状和渐变xml shape标签 corner标签:改变轮廓 gradient:颜色填充的渐变 android:angle  android:angle=“ ...