Skip to content

Commit

Permalink
Update p3046
Browse files Browse the repository at this point in the history
  • Loading branch information
HuaHuaY committed Dec 28, 2024
1 parent 694bdcb commit 2b015dd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Call test by running `cargo test p[xxx]_`.

## 现在可以公开的情报(Problems Solved)

### Easy(92)
### Easy(93)

- [1. Two Sum](src/leetcode/p1_two_sum)
- [9. Palindrome Number](src/leetcode/p9_palindrome_number)
Expand Down Expand Up @@ -99,6 +99,7 @@ Call test by running `cargo test p[xxx]_`.
- [2859. Sum of Values at Indices With K Set Bits](src/leetcode/p2859_sum_of_values_at_indices_with_k_set_bits)
- [2864. Maximum Odd Binary Number](src/leetcode/p2864_maximum_odd_binary_number)
- [2917. Find the K-or of an Array](src/leetcode/p2917_find_the_k_or_of_an_array)
- [3046. Split the Array](src/leetcode/p3046_split_the_array)
- [3083. Existence of a Substring in a String and Its Reverse](src/leetcode/p3083_existence_of_a_substring_in_a_string_and_its_reverse)
- [3162. Find the Number of Good Pairs I](src/leetcode/p3162_find_the_number_of_good_pairs_i)

Expand Down
1 change: 1 addition & 0 deletions src/leetcode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ pub mod p29_divide_two_integers;
pub mod p2_add_two_numbers;
pub mod p300_longest_increasing_subsequence;
pub mod p303_range_sum_query_immutable;
pub mod p3046_split_the_array;
pub mod p3083_existence_of_a_substring_in_a_string_and_its_reverse;
pub mod p30_substring_with_concatenation_of_all_words;
pub mod p310_minimum_height_trees;
Expand Down
29 changes: 29 additions & 0 deletions src/leetcode/p3046_split_the_array/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
pub struct Solution;

impl Solution {
pub fn is_possible_to_split(nums: Vec<i32>) -> bool {
!nums
.into_iter()
.fold([0; 100], |mut acc, x| {
acc[x as usize - 1] += 1;
acc
})
.into_iter()
.any(|i| i > 2)
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test1() {
assert!(Solution::is_possible_to_split([1, 1, 2, 2, 3, 4].to_vec()));
}

#[test]
fn test2() {
assert!(!Solution::is_possible_to_split([1, 1, 1, 1].to_vec()));
}
}

0 comments on commit 2b015dd

Please sign in to comment.