Repeated Substring Pattern
来源:互联网 发布:seo 专家 顺丰 编辑:程序博客网 时间:2024/06/06 23:58
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: True
Explanation: It’s the substring “ab” twice.
Example 2:
Input: “aba”
Output: False
Example 3:
Input: “abcabcabcabc”
Output: True
Explanation: It’s the substring “abc” four times. (And the substring “abcabc” twice.)
class Solution {public: bool repeatedSubstringPattern(string s) { string pattern = ""; for(int i = 0 ; i < s.size() ; ++i){ pattern += s[i]; if(pattern.size() == s.size()) break; if(s.size()%pattern.size()==0){ int count = s.size() / pattern.size() ; string temp = ""; while(count--){ temp+=pattern; } if(temp == s) return true; } } return false; }};
0 0
- 459. Repeated Substring Pattern
- 459. Repeated Substring Pattern
- Repeated Substring Pattern
- 459. Repeated Substring Pattern*
- 459. Repeated Substring Pattern
- Repeated Substring Pattern
- 459. Repeated Substring Pattern
- 459. Repeated Substring Pattern
- 459. Repeated Substring Pattern
- Repeated Substring Pattern
- Leetcode Repeated Substring Pattern
- 459. Repeated Substring Pattern
- LEETCODE--Repeated Substring Pattern
- 459. Repeated Substring Pattern
- 459. Repeated Substring Pattern
- 459. Repeated Substring Pattern
- 459. Repeated Substring Pattern
- 459. Repeated Substring Pattern
- [COGS826][Tyvj Feb11] GF打dota(k短路)
- bzoj 2809 左偏树
- ACM-动态规划23-大盗阿福
- 欢迎使用CSDN-markdown编辑器
- 面试题:如何找出数组里出现次数超过总数1/3的数
- Repeated Substring Pattern
- HTML(5)——<hr />添加水平线
- ACM-动态规划26-滑雪
- 2017-杭州cccc
- jQuery遍历----------(遍历、祖先、后代、同胞、过滤)
- Nginx+Tomcat多站点访问默认tomcat主页问题
- Detect Capital
- mongo索引小结
- ACM-动态规划28-Maxmum sum