Define S = [s,n] as the string S which consists of n connected strings s. For example, ["abc", 3] ="abcabcabc". On the other hand, we define that string s1 can be obtained from string s2 if we can remove some characters from s2 such th…
Define S = [s,n] as the string S which consists of n connected strings s. For example, ["abc", 3] ="abcabcabc". On the other hand, we define that string s1 can be obtained from string s2 if we can remove some characters from s2 such th…
Leetcode 466 直接给出DP方程 dp[i][k]=dp[i][k-1]+dp[(i+dp[i][k-1])%len1][k-1]; dp[i][k]表示从字符串s1的第i位开始匹配2^k个s2串需要的长度 最后通过一个循环 累积最多可以匹配多少个s2串 除以n2下取整就是答案 用倍增加速后 总的复杂度nlogn 而本题的n非常小 轻松AC 体会到倍增的魅力了吧. const int maxn=100+1,INF=1e+9; long long int dp[maxn][30]; cl…
Count and Say 计数和发言 思路:首先要理解题意,可以发现后者是在前者的基础之上进行的操作,所以我们拿之前的结果作为现在函数的参数循环n-1次即可,接下来就是统计字符串中相应字符的个数,需要注意的是最后一个字符别忘了处理. class Solution(object): def countAndSay(self, n): """ :type n: int :rtype: str """ if n < 2: return '1'…
https://leetcode.com/problems/count-the-repetitions/description/ 找循环节 https://www.cnblogs.com/grandyang/p/6149294.html…
The count-and-say sequence is the sequence of integers with the first five terms as following: 1. 1 2. 11 3. 21 4. 1211 5. 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…
Description: Count the number of prime numbers less than a non-negative number, n. 题目标签:Hash Table 题目给了我们一个n, 让我们找出比n小的 质数的数量. 因为这道题目有时间限定,不能用常规的方法. 首先建立一个boolean[] nums,里面初始值都是false,利用index 和 boolean 的对应,把所有prime number = false:non-prime number = tr…
Define S = [s,n] as the string S which consists of n connected strings s. For example, ["abc", 3] ="abcabcabc". On the other hand, we define that string s1 can be obtained from string s2 if we can remove some characters from s2 such th…
466. 统计重复个数 定义由 n 个连接的字符串 s 组成字符串 S,即 S = [s,n].例如,["abc", 3]="abcabcabc". 另一方面,如果我们可以从 s2 中删除某些字符使其变为 s1,我们称字符串 s1 可以从字符串 s2 获得.例如,"abc" 可以根据我们的定义从 "abdbec" 获得,但不能从 "acbbe" 获得. 现在给出两个非空字符串 S1 和 S2(每个最多 10…
统计重复个数 定义由 n 个连接的字符串 s 组成字符串 S,即 S = [s,n].例如,["abc", 3]="abcabcabc". 另一方面,如果我们可以从 s2 中删除某些字符使其变为 s1,我们称字符串 s1 可以从字符串 s2 获得.例如,"abc" 可以根据我们的定义从 "abdbec" 获得,但不能从 "acbbe" 获得. 现在给出两个非空字符串 S1 和 S2(每个最多 100 个字符…