Skip to content

Commit 30f25dc

Browse files
committed
two pointer to detect pattern in arr
1 parent 36ccc68 commit 30f25dc

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

1566/main.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
impl Solution {
2+
pub fn contains_pattern(arr: Vec<i32>, m: i32, k: i32) -> bool {
3+
let n = arr.len();
4+
if n < (m * k) as usize {
5+
return false;
6+
}
7+
let end = n - (m * k) as usize;
8+
let m = m as usize;
9+
for i in 0..=end {
10+
let mut res = true;
11+
for j in 1..k as usize {
12+
if arr[i..m + i] != arr[i + m * j..i + m * (j + 1)] {
13+
res = false;
14+
break;
15+
}
16+
}
17+
if res {
18+
return true;
19+
}
20+
}
21+
false
22+
}
23+
}

0 commit comments

Comments
 (0)