leetcode:Count and Say【Python版】
一次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版】的更多相关文章
- 【leetcode】Min Stack -- python版
题目描述: Design a stack that supports push, pop, top, and retrieving the minimum element in constant ti ...
- leetcode Count and Say python
class Solution(object): def countAndSay(self, n): """ :type n: int :rtype: str " ...
- leetcode:Path Sum【Python版】
1.类中递归调用函数需要加self # Definition for a binary tree node # class TreeNode: # def __init__(self, x): # s ...
- leetcode:Same Tree【Python版】
1.p或q为None的情况用开始的两个if语句进行判断: 2.类中递归调用函数需要使用self进行调用: 3.代码很简洁,最后几行通过同时为None和同时非None的条件进行判断: # Definit ...
- leetcode:Single Number【Python版】
1.用双重循环逐个遍历(超时) 2.用list B的append和remove函数(超时) 3.用dict B(AC) class Solution: # @param A, a list of in ...
- leetcode:Palindrome Number【Python版】
一次AC 题目要求中有空间限制,因此没有采用字符串由量变向中间逐个对比的方法,而是采用计算翻转之后的数字与x是否相等的方法: class Solution: # @return a boolean d ...
- leetcode:Reverse Integer【Python版】
1.在进入while之前,保证x是非负的: 2.符号还是专门用flag保存 =================== 3.另一思路:将integer转换成string,然后首位swap,直至中间: cl ...
- 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变 ...
- leetcode:Valid Palindrome【Python版】
1.注意空字符串的处理: 2.注意是alphanumeric字符: 3.字符串添加字符直接用+就可以: class Solution: # @param s, a string # @return a ...
- 数据结构:顺序表(python版)
顺序表python版的实现(部分功能未实现) #!/usr/bin/env python # -*- coding:utf-8 -*- class SeqList(object): def __ini ...
随机推荐
- Loading Xps from MemoryStream
A common way of loading XpsDocument is to load it from file: XpsDocument document = new XpsDocument( ...
- LeetCode--155--最小栈
问题描述: 设计一个支持 push,pop,top 操作,并能在常数时间内检索到最小元素的栈. push(x) -- 将元素 x 推入栈中. pop() -- 删除栈顶的元素. top() -- 获取 ...
- android--------Android Studio常见问题以及解决方式
gradle build的时候出现的问题: Error:Execution failed for task ':app:packageDebug'. Duplicate files copied in ...
- springboot实现java代理IP池 Proxy Pool,提供可用率达到95%以上的代理IP
一.背景 前段时间,写java爬虫来爬网易云音乐的评论.不料,爬了一段时间后ip被封禁了.由此,想到了使用ip代理,但是找了很多的ip代理网站,很少有可以用的代理ip.于是,抱着边学习的心态,自己开发 ...
- CentOS7.6 Install TensorFlow
1. install pip 1). yum -y install epel-release 2). yum install python-pip 3). pip install --upgra ...
- bzoj2595: [Wc2008]游览计划 斯坦纳树
斯坦纳树是在一个图中选取某些特定点使其联通(可以选取额外的点),要求花费最小,最小生成树是斯坦纳树的一种特殊情况 我们用dp[i][j]来表示以i为根,和j状态是否和i联通,那么有 转移方程: dp[ ...
- store procedure
store procedure: _________________________________________________ set ANSI_NULLS ON set QUOTED_IDEN ...
- 关于向后台请求数据(get请求,无参数传递),返回html代码(实际需要返回的是json数据)的解决方案
this.$http.get(apis.schoolVideo, { headers: { 'X-Requested-With': 'XMLHttpRequest' } }) 待续
- html 列表相关信息
无序列表 无序列表是一个项目的列表,此列项目使用粗体圆点(典型的小黑圆圆标记) 无序列表始于<ul>标签.每个列表项始于<li> <ul> <li> ...
- download fomat install rootfs script
download.sh #!/bin/sh # check the network first serverip=$(cat /tmp/serverip) while true; do ping -c ...