38. Count and Say - Unsolved
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的更多相关文章
- LeetCode - 38. Count and Say
38. Count and Say Problem's Link ------------------------------------------------------------------- ...
- LeetCode题解38.Count and Say
38. Count and Say The count-and-say sequence is the sequence of integers beginning as follows: 1, 11 ...
- 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 ...
- 【leetcode❤python】 38. Count and Say
#-*- coding: UTF-8 -*- class Solution(object): def countAndSay(self, n): """ ...
- 38. Count and Say
The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221 ...
- 【LeetCode】38 - Count and Say
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...
- Java [leetcode 38]Count and Say
题目描述: The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, ...
- 【一天一道LeetCode】#38. Count and Say
一天一道LeetCode系列 (一)题目 The count-and-say sequence is the sequence of integers beginning as follows: 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 ...
随机推荐
- JS事件处理程序
JS事件处理程序:HTML事件处理程序.DOM0级事件处理程序.DOM2级事件处理程序.IE事件处理程序.跨浏览器的事件处理程序. HTML事件处理程序 <script type="t ...
- SEO,搜索引擎优化原理方法等整体把握
SEO 搜索算法: 全文文字 title 标签,title里面的文字 link 链接 link 链接里的文字 站点信任度 最佳实践: 一.设置title 准确的描述当前网页的内容 提高站点内title ...
- Linux - PCB之task_struct结构体
task_struct结构描述 1. 进程状态(State) 进程执行时,它会根据具体情况改变状态 .进程状态是调度和对换的依据.Linux中的进程主要有如下状态,如表4.1所示. 内核表示 含义 ...
- 【lucene系列学习四】log4j日志文件实现多线程的测试
参考资料:http://nudtgk2000.iteye.com/blog/1716379 首先,在http://www.apache.org/dyn/closer.cgi/logging/log4j ...
- C#使用NOPI导入Excel
使用NOPI导入Excel文档 NOPI版本:2.3.0,依赖于NPOI的SharpZipLib版本:0.86,经测试适用于.net4.0+ 记录遇到的几个问题 NOPI中的IWorkbook接口:x ...
- MySQL 完整和增量备份与恢复
MySQL 完全备份与恢复 1.数据备份的重要性 在企业中数据的价值至关重要,数据保障了企业的业务的运行,因此数据的安全性及可靠性是运维的重中之重,任何数据的丢失都有可能会对企业产生严重的后果.造成数 ...
- 通过Servlet实现汉字验证码
package com; import java.awt.Color;import java.awt.Font;import java.awt.Graphics;import java.awt.Gra ...
- java中的GC(gabage collection)如何工作
1. “引用记数(reference counting)”是一种简单但速度很慢的垃圾回收技术.每个对象都含有一个引用记数器,当有引用连接至对象时,引用计数加1.当引用离开作用域或被置 为null时,引 ...
- 转:CentOS---网络配置详解
一.配置文件详解在RHEL或者CentOS等Redhat系的Linux系统里,跟网络有关的主要设置文件如下: /etc/host.conf 配置域名服务客户端的控制文件/etc/hos ...
- .net数据统计系统设计(中小型)
近一年多没在博客园写东西了,从换公司后就一直努力学习公司的框架和业务.而今接手一个电商数据统计项目,在博客园搜索统计项目解决方案却一无所获,最终自己设计并在开发的过程中持续更新,希望可以和大家一起交流 ...