给定一个非空的字符串,判断它是否可以由它的一个子串重复多次构成。给定的字符串只含有小写英文字母,并且长度不超过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 重复的子字符串的更多相关文章

  1. Leetcode459.Repeated Substring Pattern重复的子字符串

    给定一个非空的字符串,判断它是否可以由它的一个子串重复多次构成.给定的字符串只含有小写英文字母,并且长度不超过10000. 示例 1: 输入: "abab" 输出: True 解释 ...

  2. 459. Repeated Substring Pattern【easy】

    459. Repeated Substring Pattern[easy] Given a non-empty string check if it can be constructed by tak ...

  3. 43. leetcode 459. Repeated Substring Pattern

    459. Repeated Substring Pattern Given a non-empty string check if it can be constructed by taking a ...

  4. 【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 ...

  5. 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 ...

  6. *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 ...

  7. 459. Repeated Substring Pattern

    https://leetcode.com/problems/repeated-substring-pattern/#/description Given a non-empty string chec ...

  8. [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 ...

  9. Repeated Substring Pattern --重复字符串

    Given a non-empty string check if it can be constructed by taking a substring of it and appending mu ...

随机推荐

  1. kindle】扫描版PDF完美切割六寸

    kindle]扫描版PDF完美切割六寸  半夏 2013-11-05 18:36:01     软件来源记不清了..连使用说明的网址都找不到了,自己写一下使用方法大家凑合一下呗~    软件是大牛写的 ...

  2. Vs2012在Linux开发中的应用(5):项目属性的定义

    VS的项目属性表实际上是由一系列的XML文件定义的,都存放在C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\2052文件夹下.我们全然能够 ...

  3. Asp.net MVC 简单分页 自做简单分页

    Asp.net MVC 简单分页:   public static string Pager(int page,int pageSize,int total)         {           ...

  4. python的线程thread笔记

    python的线程是用thread和threading来实现的.其中利用threading会更好,因为thread没有线程保护,当主线程退出了之后,子线程也会被强行退出.threading支持守护线程 ...

  5. 【转】SQL中的取整函数FLOOR、ROUND、CEIL、TRUNC、SIGN

    --------------------------------------------------------------------------1 trunc(value,precision)按精 ...

  6. centos+nginx+php-fpm+php include fastcgi_params php页面能訪问但空白,被fastcgi_params与fastcgi.conf害慘了

    今天在centos上折腾这块是发现老是訪问页面时,浏览器中提示是200 ok.且訪问html后缀却是正常出现内容. 可是訪问php后缀却返回空白页面,同一时候查看全部的log没有发现不论什么出错信息; ...

  7. Android项目之HomeHealth基础学习2:Service

    一. Service简单介绍 Service是android 系统中的四大组件之中的一个(Activity.Service.BroadcastReceiver.ContentProvider),它跟A ...

  8. POJ 1936 All in All(串)

    All in All Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 27537 Accepted: 11274 Descript ...

  9. What to do about Eclipse's “No repository found containing: …” error messages?

    As Mauro said: "you have to remove and re-add the Eclipse Project Update site, so that its meta ...

  10. Android AR场景拍照技术实现(有关键源代码)

    ARVR技术交流群:129340649 欢迎增加. AR场景往往给别人留下的印象深刻,假设模型做的炫丽一点,效果将会更好. 那么怎样保存这一美好的情景呢?这篇文章将教你怎样实现AR场景的拍摄以及永久保 ...