diff options
author | Jack Sangdahl <[email protected]> | 2025-06-27 12:23:02 -0600 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2025-06-27 12:23:02 -0600 |
commit | a96b65cbfad7f62f3db6b2eab105e4e25c0414c5 (patch) | |
tree | e2a2b3f49f9fb741be81415266ac93e74cff42ec /other/num_bad_pairs.rs | |
parent | 694ad5ed71edcb1deccab54b72d706b779918276 (diff) | |
download | leetcode-a96b65cbfad7f62f3db6b2eab105e4e25c0414c5.tar.gz leetcode-a96b65cbfad7f62f3db6b2eab105e4e25c0414c5.zip |
chore: remove old cpp and rust solutions
Diffstat (limited to 'other/num_bad_pairs.rs')
-rw-r--r-- | other/num_bad_pairs.rs | 30 |
1 files changed, 0 insertions, 30 deletions
diff --git a/other/num_bad_pairs.rs b/other/num_bad_pairs.rs deleted file mode 100644 index 88119d8..0000000 --- a/other/num_bad_pairs.rs +++ /dev/null @@ -1,30 +0,0 @@ -// 2364. Count Number of Bad Pairs -use std::collections::HashMap; -struct Solution; - -/* - * you are given a 0-indexed integer array 'nums'. a pair of indices '(i, j)' is - * a bad pair if 'i < j' and 'j - i != nums[j] - nums[i]'. return the total - * number of bad pairs in 'nums'. - */ - -impl Solution { - pub fn count_bad_pairs(nums: Vec<i32>) -> i64 { - let mut hm: HashMap<i32, i32> = HashMap::with_capacity(nums.len()); - let mut ans = 0; - nums.iter().zip(0..).for_each(|(&x, i)| { - let delta = x - i; - let e = hm.entry(delta).or_default(); - ans += (i - *e) as i64; - *e += 1; - }); - ans - } -} - -fn main() { - let n1 = vec![4, 1, 3, 3]; - let n2 = vec![1, 2, 3, 4, 5]; - println!("{}", Solution::count_bad_pairs(n1)); //expect: 5 - println!("{}", Solution::count_bad_pairs(n2)); //expect: 0 -} |