-
Notifications
You must be signed in to change notification settings - Fork 2
/
q0459.hpp
58 lines (54 loc) · 1.43 KB
/
q0459.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
// q0459.hpp
// LeetCode
//
// Created by NowOrNever on 03/09/2020.
// Copyright © 2020 DoubleL. All rights reserved.
//
#ifndef q0459_hpp
#define q0459_hpp
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <numeric>
#include <stack>
#include <string>
using namespace std;
void question0459(){
class Solution {
private:
bool isVaildNumber(string s, int len, int times){
for (int i = 0; i < len; i++) {
for (int j = 1; j < times; j++) {
if (s[i] != s[j * len + i]) {
return false;
}
}
}
return true;
}
public:
bool repeatedSubstringPattern(string s) {
int length = (int)s.size();
vector<bool> flags(length + 1, true);
for (int i = 2; i <= length; i++) {
if (flags[i]){
if (length % i == 0 && isVaildNumber(s, length / i, i)) {
return true;
}
for (int j = 2; j * i <= length; j++) {
flags[i * j] = false;
}
}
}
return false;
}
};
bool result = Solution().repeatedSubstringPattern("ababababab");
cout << result << endl;
}
#endif /* q0459_hpp */