Count and Say leetcode

题目链接

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.

题意是n=1时输出字符串1;n=2时,数上次字符串中的数值个数,因为上次字符串有1个1,所以输出11;n=3时,由于上次字符是11,有2个1,所以输出21;n=4时,由于上次字符串是21,有1个2和1个1,所以输出1211。依次类推,写个countAndSay(n)函数返回字符串。

http://blog.csdn.net/kenden23/article/details/17081853

时间: 2024-08-08 17:56:24

Count and Say leetcode的相关文章

Count and Say leetcode java

题目: 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. Gi

204. Count Primes(LeetCode)

Description: Count the number of prime numbers less than a non-negative number, n. 1 class Solution { 2 public: 3 int countPrimes(int n) { 4 vector<bool> num(n - 1, true); 5 num[0] = false; 6 int res = 0, limit = sqrt(n); 7 for (int i = 2; i <= l

696. Count Binary Substrings - LeetCode

Question 696. Count Binary Substrings Example 1: Input: "00110011" Output: 6 Explanation: There are 6 substrings that have equal number of consecutive 1's and 0's: "0011", "01", "1100", "10", "0011&qu

LeetCode: Count and Say [037]

[题目] 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. G

Solution to LeetCode Problem Set

Here is my collection of solutions to leetcode problems. LeetCode - Course Schedule LeetCode - Reverse Linked List LeetCode - Isomorphic Strings LeetCode - Count Primes LeetCode - Remove Linked List Elements LeetCode - Happy Number LeetCode - Bitwise

LeetCode OJ--Minimum Window Substring ***

https://oj.leetcode.com/problems/minimum-window-substring/ 模拟题 这道题细节比较多.从左到右扫一遍模拟着做 class Solution { public: string minWindow(string S, string T) { string ans = ""; if(S.size() < T.size() ) return ans; unordered_map<char,int> count; uno

LeetCode记录之26——Remove Duplicates from Sorted Array

国外的表达思维跟咱们有很大差别,做这道题的时候很明显.简单说本题就是让你把有序数组中的重复项给换成正常有序的.比如 1 2 2 3换成 1 2 3 3,根本不需要考虑重复的怎么办,怎么删除重复项等等.拿起键盘干就行了.然后返回有序项的下标就可以. Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not

LeetCode 第一题剪彩自己的leetCode之路

Reverse Words in a String Given an input string, reverse the string word by word. For example, Given s = "the sky is blue", return "blue is sky the". click to show clarification. Clarification: What constitutes a word? A sequence of no

leetcode 之digit

leetcode 1067. Digit Count in Range leetcode 233. Number of Digit One leetcode 902. Numbers At Most N Given Digit Set leetcode 1088. Confusing Number II 都是求<=N的数中满足某种条件的数字数量 leetcode 1067. Digit Count in Range leetcode 233. Number of Digit One 这不单单是求