459. Repeated Substring Pattern
来源:互联网 发布:手机数据连接总是断开 编辑:程序博客网 时间:2024/06/05 11:49
Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase English letters only and its length will not exceed 10000.
Example 1:
Input: "abab"Output: TrueExplanation: It's the substring "ab" twice.
Example 2:
Input: "aba"Output: False
Example 3:
Input: "abcabcabcabc"Output: TrueExplanation: It's the substring "abc" four times. (And the substring "abcabc" twice.)
Subscribe to see which companies asked this question.
判断字符串是否是由一个子字符串重复得来。使用暴力的方法,把字符串分别等分成长度为1,2...n/2的子字符串来进行比较。只要分成的每个子字符串都想等,就返回true。
代码:
class Solution{public:bool repeatedSubstringPattern(string s){int n = s.size(), i, j;for(i = 1; i <= n / 2; ++i){if(n % i != 0) continue;string tmp = s.substr(0, i);for(j = i; j < n; j += i){if(s.substr(j, i) != tmp) break;}if(j == n) return true;}return false;}};
阅读全文
0 0
- 459. Repeated Substring Pattern
- 459. Repeated Substring Pattern
- 459. Repeated Substring Pattern*
- 459. Repeated Substring Pattern
- 459. Repeated Substring Pattern
- 459. Repeated Substring Pattern
- 459. Repeated Substring Pattern
- 459. Repeated Substring Pattern
- 459. Repeated Substring Pattern
- 459. Repeated Substring Pattern
- 459. Repeated Substring Pattern
- 459. Repeated Substring Pattern
- 459. Repeated Substring Pattern
- 459. Repeated Substring Pattern
- 459. Repeated Substring Pattern
- 459. Repeated Substring Pattern
- 459. Repeated Substring Pattern
- 459. Repeated Substring Pattern
- Unity游戏UI框架(七):消息传递中心
- javascript 面向对象(六)原型的特性和作用
- Windows 系统下配置 pyrouge
- 接口测试入门
- 系统测试——基础知识
- 459. Repeated Substring Pattern
- windows 配置不同版本JDK
- nginx简单配置
- 《C++ primer》读书规划 I
- Java8 Lambda表达式 函数式编程(转)
- Linux日常——PSH&URG,定时器,三次握手&四次挥手
- JDBC实现连接池
- 线性代数的本质-学习笔记3
- wamp自定义网站根目录