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 ...
随机推荐
- http://vdceye.com/ 全新页面上线
vdceye manager home page
- Deepin-安装QQ音乐(Windows程序)
打开命令行,输入: sudo apt-get install wine 安装完成后,下载QQ音乐的安装包 然后安装 示例:wine xx.exe 实例:wine QQMusic.exe 安装完成,启动 ...
- 剑指Offer面试题15(Java版):链表中倒数第K个结点
题目: 输入一个链表.输出该链表中倒数第k哥结点. 为了符合大多数人的习惯,本题从1開始计数.即链表的尾结点是倒数第1个结点. 比如一个链表有6个结点.从头结点開始它们的值依次是1.2.3,4,5, ...
- MySQL基础笔记(六) 存储过程与函数
写在开头:本文所有的示例都是基于workers表,表中保存了某公司的员工姓名.性别.工资.年龄和居住城市,如下: +----+-----------+--------+--------+------+ ...
- MYSQL将时间格式化
SELECT *,DATE_FORMAT(FROM_UNIXTIME(createtime), "%Y/%m/%d %H:%i:%s") AS dateFormat FROM `I ...
- boost的内存管理
smart_ptr raii ( Resource Acquisition Is Initialization ) 智能指针系列的都统称为smart_ptr.包含c++98标准的auto_ptr 智能 ...
- VUEX action解除页面耦合
最近项目中需要用到vue+vuex来实现登出跳转功能,老大指派任务要用action解除页面耦合,刚从vue深渊晕晕乎乎爬出来的我是一脸懵逼啊...啥是解除耦合...网上vuex的资料太少了,vuex手 ...
- 安卓版本和Api Level
Platform Version API Level VERSION_CODE Notes Android 4.4 19 KITKAT Platform Highlights Android 4.3 ...
- 网页中打开exe
网页上打开本地的exe文件,可以吗? 西蒙说:可以的. 方法如下: 1.定义一个私有协议,指向本地的那个exe 2.在网页上将此私有协议作为URL,点击之即可打开那个exe 3.URL中还可以包含参数 ...
- WEB 字体
之前如果想在自己的网站使用某些好看的字体,总是迫不得已得在PS里先把字体图片做好.虽然这样做也能达到我们想要的效果,但是这样就增加了HTTP请求 (如果在多处使用的话),即使合并所有图片,也不好管理, ...