We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent fe3c3c7 commit ec6c7f5Copy full SHA for ec6c7f5
scripts/algorithms/R/Repeated Substring Pattern/Repeated Substring Pattern.rs
@@ -0,0 +1,25 @@
1
+// Runtime: 0 ms (Top 100.0%) | Memory: 2.00 MB (Top 94.32%)
2
+
3
+impl Solution {
4
+ pub fn repeated_substring_pattern(s: String) -> bool {
5
+ for i in 0..s.len()/2 {
6
+ let n = s.len();
7
+ if n as u32 % (i as u32 + 1) != 0 {
8
+ continue;
9
+ }
10
+ let sub = &s[..i+1];
11
+ let mut rep = true;
12
+ for j in 1..n/sub.len() {
13
+ let a = sub.len() * j;
14
+ if s[a..a+sub.len()] != *sub {
15
+ rep = false;
16
+ break;
17
18
19
+ if rep == true {
20
+ return true;
21
22
23
+ return false;
24
25
+}
0 commit comments