3583. 统计特殊三元组
This commit is contained in:
parent
376065acb6
commit
9a82ec82f7
25
src/main.rs
25
src/main.rs
|
|
@ -1,19 +1,30 @@
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
struct Solution;
|
struct Solution;
|
||||||
mod arr;
|
mod arr;
|
||||||
impl Solution {
|
impl Solution {
|
||||||
pub fn count_permutations(complexity: Vec<i32>) -> i32 {
|
pub fn special_triplets(nums: Vec<i32>) -> i32 {
|
||||||
|
let mut map: HashMap<i32, i32> = HashMap::new();
|
||||||
|
let mut map2: HashMap<i32, i32> = HashMap::new();
|
||||||
let md = 1e9 as i64 + 7;
|
let md = 1e9 as i64 + 7;
|
||||||
let mut ans = 1_i64;
|
let mut ans = 0_i64;
|
||||||
for i in 1..complexity.len() {
|
nums.iter().for_each(|x| {
|
||||||
if complexity[i] <= complexity[0] {
|
map.insert(*x, map.get(&x).copied().unwrap_or(0) + 1);
|
||||||
return 0;
|
});
|
||||||
|
map2.insert(nums[0], 1);
|
||||||
|
for i in 1..nums.len() - 1 {
|
||||||
|
let mp2d = map2.get(&(nums[i] * 2)).copied().unwrap_or(0) as i64;
|
||||||
|
let mut mp1d = map.get(&(nums[i] * 2)).copied().unwrap_or(0) as i64 - mp2d;
|
||||||
|
if nums[i] == nums[i] * 2 {
|
||||||
|
mp1d -= 1;
|
||||||
}
|
}
|
||||||
ans = (ans * i as i64) % md;
|
ans = (ans + mp1d * mp2d) % md;
|
||||||
|
map2.insert(nums[i], map2.get(&nums[i]).copied().unwrap_or(0) + 1);
|
||||||
}
|
}
|
||||||
ans as i32
|
ans as i32
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn main() {
|
fn main() {
|
||||||
let result = Solution::count_permutations(vec![1, 3, 3, 4, 4, 4]);
|
let result = Solution::special_triplets(vec![0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);
|
||||||
println!("{:?}", result);
|
println!("{:?}", result);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue