459 Repeated Substring Pattern 重复的子字符串
给定一个非空的字符串,判断它是否可以由它的一个子串重复多次构成。给定的字符串只含有小写英文字母,并且长度不超过10000。
示例 1:
输入: "abab"
输出: True
解释: 可由子字符串 "ab" 重复两次构成。
示例 2:
输入: "aba"
输出: False
示例 3:
输入: "abcabcabcabc"
输出: True
解释: 可由子字符串 "abc" 重复四次构成。 (或者子字符串 "abcabc" 重复两次构成。)
详见:https://leetcode.com/problems/repeated-substring-pattern/description/
C++:
class Solution {
public:
bool repeatedSubstringPattern(string str)
{
int n = str.size();
for (int i = n / 2; i >= 1; --i)
{
if (n % i == 0)
{
int c = n / i;
string t = "";
for (int j = 0; j < c; ++j)
{
t += str.substr(0, i);
}
if (t == str)
{
return true;
}
}
}
return false;
}
};
参考:https://www.cnblogs.com/grandyang/p/6087347.html
459 Repeated Substring Pattern 重复的子字符串的更多相关文章
- Leetcode459.Repeated Substring Pattern重复的子字符串
给定一个非空的字符串,判断它是否可以由它的一个子串重复多次构成.给定的字符串只含有小写英文字母,并且长度不超过10000. 示例 1: 输入: "abab" 输出: True 解释 ...
- 459. Repeated Substring Pattern【easy】
459. Repeated Substring Pattern[easy] Given a non-empty string check if it can be constructed by tak ...
- 43. leetcode 459. Repeated Substring Pattern
459. Repeated Substring Pattern Given a non-empty string check if it can be constructed by taking a ...
- 【LeetCode】459. Repeated Substring Pattern
Given a non-empty string check if it can be constructed by taking a substring of it and appending mu ...
- LeetCode 459 Repeated Substring Pattern
Problem: Given a non-empty string check if it can be constructed by taking a substring of it and app ...
- *459. Repeated Substring Pattern (O(n^2)) two pointers could be better?
Given a non-empty string check if it can be constructed by taking a substring of it and appending mu ...
- 459. Repeated Substring Pattern
https://leetcode.com/problems/repeated-substring-pattern/#/description Given a non-empty string chec ...
- [LeetCode] 459. Repeated Substring Pattern 重复子字符串模式
Given a non-empty string check if it can be constructed by taking a substring of it and appending mu ...
- Repeated Substring Pattern --重复字符串
Given a non-empty string check if it can be constructed by taking a substring of it and appending mu ...
随机推荐
- Office EXCEL 如何将复制的一堆数据按空格断开
1 复制粘贴一堆数据,点击数据-分类,然后点击下一步 2 一直下一步 3 最后效果如下图所示
- 【LeetCode-面试算法经典-Java实现】【066-Plus One(加一)】
[066-Plus One(加一)] [LeetCode-面试算法经典-Java实现][全部题目文件夹索引] 原题 Given a non-negative number represented as ...
- Mapreduce运行过程分析(基于Hadoop2.4)——(三)
4.4 Reduce类 4.4.1 Reduce介绍 整完了Map,接下来就是Reduce了.YarnChild.main()->ReduceTask.run().ReduceTask.run方 ...
- Pierce振荡器设计
一.Pierce振荡器电路 Inv:内部反相器,作用等同于放大器: Q:石英晶体或陶瓷晶振: RF:内部反馈电阻(使反相器工作在线性区): RExt:外部限流电阻(防止石英晶体被过分驱动): CL1. ...
- C语言的各种位运算符的操作简述
运算符: 算术运算符: + , - , * , / , % , ++ , -- 符合运算符: += , *= , /= , %= 条件运算符: ? : 关系运算符: == , >= , < ...
- Receiver type ‘X’ for instance message is a forward declaration
这往往是引用的问题. ARC要求完整的前向引用,也就是说在MRC时代可能仅仅须要在.h中申明@class就能够,可是在ARC中假设调用某个子类中未覆盖的父类中的方法的话.必须对父类.h引用,否则无法编 ...
- hdu 2059 龟兔赛跑 (dp)
/* 把起点和终点比作加油站,那总共同拥有n+2个加油站了, 每次都求出从第0个到第j个加油站(j<i)分别在加满油的情况下到第i个加油站的最短时间dp[i], 终于的dp[n+1]就是最优解了 ...
- [办公应用]让WORD自动显示到四级目录
一般情况下,word的目录默认显示到三级目录.如果需要显示到四级目录,你会怎么操作呢? 只要按下图所示,单击“插入”-“引用”-“索引和目录” 然后单击“目录”选项卡,将“显示级别”处的3改为4即可. ...
- python和python3
1 安装python和python3的方法 如果是python,那么直接python setup.py install; 如果是python3,那么直接python3 setup.py install ...
- 系统队列中的Windows错误报告