leetcode 38 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.

题目地址:leetcode Count and Say

题目大意:

n=1 返回1

n=2由于n=1的结果为1,有1个1,所以返回11

n=3由于n=2结果为11,有2个1,返回21

n=4由于n=3结果为21,有1个2和1个1,所以返回1211

给定n,以此类推

 

C++

Python

 

更多题解可以查看: https://www.hrwhisper.me/leetcode-algorithm-solution/

本博客若无特殊说明则由 hrwhisper 原创发布
转载请点名出处:细语呢喃 > leetcode 38 Count and Say
本文地址:https://www.hrwhisper.me/leetcode-count-and-say/

听说长得好看的已经打赏了

codes, Leetcode . permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *