|
|
|
@ -16,32 +16,20 @@ fn main() {
|
|
|
|
|
|
|
|
|
|
fn repeated_groups(nums: Vec<isize>) -> Vec<Vec<isize>> {
|
|
|
|
|
let mut i = 0;
|
|
|
|
|
let mut j = 0;
|
|
|
|
|
let mut j = i + 1;
|
|
|
|
|
|
|
|
|
|
let mut res: Vec<Vec<isize>> = vec![];
|
|
|
|
|
let mut curr: Vec<isize> = vec![];
|
|
|
|
|
|
|
|
|
|
while j < nums.len() {
|
|
|
|
|
if nums[i] != nums[j] {
|
|
|
|
|
if curr.len() > 1 {
|
|
|
|
|
res.push(curr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i = j;
|
|
|
|
|
while j < nums.len() && nums[i] == nums[j] {
|
|
|
|
|
j += 1;
|
|
|
|
|
curr = vec![nums[i]];
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
curr.push(nums[i]);
|
|
|
|
|
j += 1;
|
|
|
|
|
if j - i > 1 {
|
|
|
|
|
res.push(nums[i..j].to_vec());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the last iteration is a repeated group, the loop exits before appending
|
|
|
|
|
// the last group to the results, so we check here for what the last group was
|
|
|
|
|
// and add it to the result if need be.
|
|
|
|
|
if curr.len() > 1 {
|
|
|
|
|
res.push(curr);
|
|
|
|
|
i = j;
|
|
|
|
|
j += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res
|
|
|
|
|