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

    是不是很happy呢? 可以用键盘替代鼠标点点点了! 1.鼠标移到右下角 2.下翻找到"快捷键" 3.自定义一个 4.示例(首先编写个简单的Shell) 程序一般放在/usr/bi ...

  2. [Hibernate Search] (3) 基础查询

    基础查询 眼下我们仅仅用到了基于keyword的查询,实际上Hibenrate Search DSL还提供了其他的查询方式,以下我们就来一探到底. 映射API和查询API 对于映射API.我们能够通过 ...

  3. anaconda中新rdkit安装

    1. 执行 conda create -c rdkit -n my-rdkit-env rdkit 该步骤经测试发现需FQ,而模拟器无法完成FQ(至少我不知道方法), 因此在本机上配置好环境后复制粘贴 ...

  4. Javascript中的apply、call、bind

    apply . call .bind 三者都是用来改变函数的this对象的指向的: apply . call .bind 三者第一个参数都是this要指向的对象,也就是想指定的上下文: apply . ...

  5. File to byte[] in Java

    File to byte[] in Java - Stack Overflow https://stackoverflow.com/questions/858980/file-to-byte-in-j ...

  6. Java 负载均衡

    什么是负载均衡 负载均衡,英文 名称为Load Balance,指由多台服务器以对称的方式组成一个服务器集合,每台服务器都具有等价的地位,都可以单独对外提供服务而无须其他服务器的辅助.通过某种 负载分 ...

  7. CRM IFD 部署在同一台服务器上遇到的错误

    为了学习Dynamics 365,在阿里去上部署一台Dynamics 365服务器.然后实现了IFD 部署.学习的路线还之前的CRM 版本大致一样,这里只是记录一下我遇到的问题及解决问题的思路. 学习 ...

  8. C#温度报警

    using System; using System.Collections.Generic; using System.Text; using System.Collections; using S ...

  9. bzoj 1504 郁闷的出纳员

    题目大意: 有一些员工 他们有工资 当他们的工资低于一个值时 他们会永远离开 I命令 I_k 新建一个工资档案,初始工资为k.                 如果某员工的初始工资低于工资下界,他将立 ...

  10. java虚拟机内存区域理解

    java虚拟机有的区域随着虚拟机进程的启动而存在, 有的区域依赖用户线程的启动和结束而建立和销毁. 程序计数器:为了线程切换后能恢复到正确的执行位置,每个线程都有一个独立的程序计数器.(针对java方 ...