File tree 3 files changed +50
-1
lines changed
0001-0500/0459-Repeated-Substring-Pattern/cpp-0459 3 files changed +50
-1
lines changed Original file line number Diff line number Diff line change
1
+ cmake_minimum_required (VERSION 3.25)
2
+ project (cpp_0459)
3
+
4
+ set (CMAKE_CXX_STANDARD 17)
5
+
6
+ add_executable (cpp_0459 main.cpp)
Original file line number Diff line number Diff line change
1
+ // / Source : https://leetcode.com/problems/repeated-substring-pattern/description/
2
+ // / Author : liuyubobobo
3
+ // / Time : 2023-08-21
4
+
5
+ #include < iostream>
6
+
7
+ using namespace std ;
8
+
9
+
10
+ // / Brute Force
11
+ // / Time Complexity: O(sqrt(n) * n)
12
+ // / Space Complexity: O(n)
13
+ class Solution {
14
+ public:
15
+ bool repeatedSubstringPattern (string s) {
16
+
17
+ int n = s.size ();
18
+ if (n == 1 ) return false ;
19
+ for (int i = 1 ; i * i <= n; i ++){
20
+ if (n % i) continue ;
21
+
22
+ if (ok (n, s, i)) return true ;
23
+
24
+ if (i * i == n || i == 1 ) continue ;
25
+ if (ok (n, s, n / i)) return true ;
26
+ }
27
+ return false ;
28
+ }
29
+
30
+ private:
31
+ bool ok (int n, const string& s, int len){
32
+ string subs = s.substr (0 , len);
33
+ for (int i = len; i <= n - len; i += len)
34
+ if (s.substr (i, len) != subs) return false ;
35
+ return true ;
36
+ }
37
+ };
38
+
39
+
40
+ int main () {
41
+
42
+ return 0 ;
43
+ }
Original file line number Diff line number Diff line change 493
493
| 456 | [ 132 Pattern] ( https://leetcode.com/problems/132-pattern/ ) | [ solution] ( https://leetcode.com/problems/132-pattern/solution/ ) <br /> [ 缺:O(n) 单调栈算法] | [ C++] ( 0001-0500/0456-132-Pattern/cpp-0456/ ) | | |
494
494
| 457 | [ Circular Array Loop] ( https://leetcode.com/problems/circular-array-loop/ ) | [ 无] | [ C++] ( 0001-0500/0457-Circular-Array-Loop/cpp-0457/ ) | | |
495
495
| 458 | [ Poor Pigs] ( https://leetcode.com/problems/poor-pigs/ ) | [ solution] ( https://leetcode.com/problems/poor-pigs/solution/ ) | [ C++] ( 0001-0500/0458-Poor-Pigs/ ) | | |
496
- | | | | | | |
496
+ | 459 | [ Repeated Substring Pattern ] ( https://leetcode.com/problems/repeated-substring-pattern/description/ ) | [ 无 ] | [ C++ ] ( 0001-0500/0459-Repeated-Substring-Pattern/cpp-0459/ ) | | |
497
497
| 460 | [ LFU Cache] ( https://leetcode.com/problems/lfu-cache/description/ ) | [ solution] ( https://leetcode.com/problems/lfu-cache/solutions/2815229/lfu-cache/?orderBy=most_votes ) | [ C++] ( 0001-0500/0460-LFU-Cache/ ) | | |
498
498
| 461 | [ Hamming Distance] ( https://leetcode.com/problems/hamming-distance/ ) | [ solution] ( https://leetcode.com/problems/hamming-distance/solution/ ) | [ C++] ( 0001-0500/0461-Hamming-Distance/cpp-0461/ ) | | |
499
499
| 462 | [ Minimum Moves to Equal Array Elements II] ( https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii/ ) | [ solution] ( https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii/solution/ ) | [ C++] ( 0001-0500/0462-Minimum-Moves-to-Equal-Array-Elements-II/cpp-0462/ ) | | |
You can’t perform that action at this time.
0 commit comments