一次AC

字符串就是:count+char

 class Solution:
# @return a string
def countAndSay(self, n):
str = ""
for i in range(n-1):
tmp = str
str = ""
c = tmp[0]
cnt = 1
for j in range(1,len(tmp)):
if tmp[j] == tmp[j-1]:
cnt += 1
else:
str += ("%d"%cnt + tmp[j-1])
cnt = 1
str += ("%d"%cnt + tmp[len(tmp)-1])
return str

leetcode:Count and Say【Python版】的更多相关文章

  1. 【leetcode】Min Stack -- python版

    题目描述: Design a stack that supports push, pop, top, and retrieving the minimum element in constant ti ...

  2. leetcode Count and Say python

    class Solution(object): def countAndSay(self, n): """ :type n: int :rtype: str " ...

  3. leetcode:Path Sum【Python版】

    1.类中递归调用函数需要加self # Definition for a binary tree node # class TreeNode: # def __init__(self, x): # s ...

  4. leetcode:Same Tree【Python版】

    1.p或q为None的情况用开始的两个if语句进行判断: 2.类中递归调用函数需要使用self进行调用: 3.代码很简洁,最后几行通过同时为None和同时非None的条件进行判断: # Definit ...

  5. leetcode:Single Number【Python版】

    1.用双重循环逐个遍历(超时) 2.用list B的append和remove函数(超时) 3.用dict B(AC) class Solution: # @param A, a list of in ...

  6. leetcode:Palindrome Number【Python版】

    一次AC 题目要求中有空间限制,因此没有采用字符串由量变向中间逐个对比的方法,而是采用计算翻转之后的数字与x是否相等的方法: class Solution: # @return a boolean d ...

  7. leetcode:Reverse Integer【Python版】

    1.在进入while之前,保证x是非负的: 2.符号还是专门用flag保存 =================== 3.另一思路:将integer转换成string,然后首位swap,直至中间: cl ...

  8. leetcode:Symmetric Tree【Python版】

    #error caused by:#1:{} 没有考虑None输入#2:{1,2,2} 没有控制h和t#3:{4,-57,-57,#,67,67,#,#,-97,-97} 没有考虑负号,将s从str变 ...

  9. leetcode:Valid Palindrome【Python版】

    1.注意空字符串的处理: 2.注意是alphanumeric字符: 3.字符串添加字符直接用+就可以: class Solution: # @param s, a string # @return a ...

  10. 数据结构:顺序表(python版)

    顺序表python版的实现(部分功能未实现) #!/usr/bin/env python # -*- coding:utf-8 -*- class SeqList(object): def __ini ...

随机推荐

  1. English trip -- VC(情景课) 8 A Get ready

    Words cashier  # 收银员                a cashier counts money   收钱 custodian  # 清洁工     a custodian  cl ...

  2. Confluence 6 从外部目录中同步数据如何工作

    下面是有关缓存功能的一些摘要信息: 用户和用户组的缓存信息保存在应用程序的数据库中. 当你连接一个新的外部目录到系统中的时候,一个同步任务将会启动被,并且在后台运行拷贝所有需要的用户和用户组信息,以及 ...

  3. FasfDFS intall nginx with image filter

    centOS7 x64 1. install gd-devel 2. ./configure --prefix=/usr/local/nginx --with-http_image_filter_mo ...

  4. c面试题总结

    1. char *pname=new char[10];pname="asdzxc"; cout<<pname: delete pname: 该程序运行时会崩溃,原因时 ...

  5. _Python定义方法

    def 定义一个方法 在项目编程中,我们往往要做很多重复的事,比如一个排序的功能(当然Python中内置排序的方法),在编程中,我们肯定是会多次用到这个功能的,如果我们每次都在要用这个功能时,都去写一 ...

  6. SQL Server SqlCacheDependency 缓存依赖

     SQL server数据缓存依赖有两种实现模式,轮询模式,通知模式. 1  轮询模式实现步骤 此模式需要SQL SERVER 7.0/2000/2005版本以上版本都支持 主要包含以下几步:  1. ...

  7. c#重写和重载的区别?重写和重载的意义?

    重写: 要求方法名.参数合返回值相同: 意义:重写是为了增强类的重用性和复用性,扩展性:重写是对类中方法的扩充,因为继承用的是父类的东西,重写则不仅得到父类的东西,同时也加入了自己的东西. 方法重写的 ...

  8. bzoj1215

    题解: 暴力枚举每一种方案,然后hash判重 代码: #include<bits/stdc++.h> #define eps 1e-7 using namespace std; ],r[] ...

  9. Java——File类概述

    body, table{font-family: 微软雅黑} table{border-collapse: collapse; border: solid gray; border-width: 2p ...

  10. <NET CLR via c# 第4版>笔记 第19章 可空值类型

    System.Nullable<T> 是结构. 19.1 C# 对可空值类型的支持 C# 允许用问号表示法来声明可空值类型,如: Int32? x = 5; Int32? y = null ...