leetcode 459. Repeated Substring Pattern 暴力拆分即可
来源:互联网 发布:当当读书网络连接失败 编辑:程序博客网 时间:2024/06/15 17:42
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.)
这道题题意很简单,最长我以为要分析字符的情况,后来发现直接暴力拆分即可,这样更简单,就这么做吧
代码如下:
#include <iostream>#include <vector>#include <map>#include <set>#include <queue>#include <stack>#include <string>#include <climits>#include <algorithm>#include <sstream>#include <functional>#include <bitset>#include <cmath>using namespace std;class Solution {public: bool repeatedSubstringPattern(string s) { for (int i = s.length() / 2; i >= 1; i--) { if (s.length() % i == 0) { int c = s.length() / i; string tmp = ""; for (int j = 0; j < c; j++) tmp += s.substr(0, i); if (tmp == s) return true; } } return false; }};
阅读全文
0 0
- leetcode 459. Repeated Substring Pattern 暴力拆分即可
- LeetCode 459. Repeated Substring Pattern
- Leetcode-459. Repeated Substring Pattern
- leetcode 459. Repeated Substring Pattern
- LeetCode 459. Repeated Substring Pattern
- 【LeetCode】 459. Repeated Substring Pattern
- LeetCode 459. Repeated Substring Pattern
- Leetcode 459. Repeated Substring Pattern
- LeetCode-459. Repeated Substring Pattern
- Leetcode 459. Repeated Substring Pattern
- 【Leetcode】459. Repeated Substring Pattern
- leetcode:459. Repeated Substring Pattern
- [LeetCode]459. Repeated Substring Pattern
- LeetCode 459. Repeated Substring Pattern
- LeetCode 459. Repeated Substring Pattern
- Leetcode 459. Repeated Substring Pattern
- LeetCode-459. Repeated Substring Pattern
- [LeetCode]459. Repeated Substring Pattern
- Gradle error : Write access is allowed from event dispatch thread only in android studio
- BAT批处理脚本--常用命令
- angular 出现"Unexpected end of JSON input while parsing near"错误解决方法
- python 实现简单爬虫
- DevExpress v17.2新版亮点—WPF篇(二)
- leetcode 459. Repeated Substring Pattern 暴力拆分即可
- QRCode使用Encoding.UTF8编码时,报错
- 深度学习记录随笔-持续更新
- Jquery 总结
- opencv笔记之模板匹配
- App 压力测试——Monkey Script常用命令介绍
- Ubuntu14.04下 安装OpenSSL 部署腾讯云免费版DV SSL证书
- Centos7安装node
- 第十五周项目1(3)-验证算法(冒泡排序)