38. Count and Say [easy] (Python)

题目链接

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

题目原文

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.

题目翻译

一个”数和说(count and say)“序列是像这样的一个整数序列:1, 11, 21, 1211, 111221, ...
1 读作 "1个1"11.
11 读作 "2个1"21.
21 读作 "1个2,1个1"1211.
给定整数n,生成第n个序列。
注意:整数序列用字符串表示。

思路方法

这个问题重点首先是要读懂题目。然后在想这个过程的时候,你可能会想的比较复杂,比如,会不会出现连续十几个一样的数字,比如1111111111,读作“ten 1”,然后转换成101。实际上,有大神已经证明,这个序列里的数不会超过4。这边搬运了一下。
原链接:https://leetcode.com/discuss/6762/how-to-proof-the-count-is-always-less-than-10

Proof by exhaustion and contrapositive:

In order for a number greater than 4 to be created, there must be a series of numbers n>4 in length all the same digit. Therefore, there is a subset of th

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值