Skip to content

Commit e993804

Browse files
committed
solve(3046): implement solution using counts of itertools
1 parent 809a84d commit e993804

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use itertools::Itertools;
2+
3+
use crate::solutions::Solution;
4+
5+
impl Solution {
6+
pub fn is_possible_to_split(nums: Vec<i32>) -> bool {
7+
!nums.iter().counts().iter().any(|(_, &count)| count > 2)
8+
}
9+
}
10+
11+
#[test]
12+
fn test() {
13+
assert!(Solution::is_possible_to_split(vec![1, 1, 2, 2, 3, 4]));
14+
assert!(!Solution::is_possible_to_split(vec![1, 1, 1, 1]))
15+
}

src/solutions/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ pub mod _0009_palindrome_number;
33
pub mod _0020_valid_parentheses;
44
pub mod _0026_remove_duplicates_from_sorted_array;
55
pub mod _0027_remove_element;
6+
pub mod _3046_split_the_array;
67

78
pub struct Solution {}

0 commit comments

Comments
 (0)