new problems solved, fixed old problems
parent
7810486dd6
commit
9e10c5f9e9
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "continuous-subarray-sum"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
@ -0,0 +1,34 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
impl Solution {
|
||||
pub fn check_subarray_sum(nums: Vec<i32>, k: i32) -> bool {
|
||||
let mut map: HashMap<i32, i32> = HashMap::new();
|
||||
map.insert(0, -1);
|
||||
let mut sum = 0;
|
||||
for i in 0..nums.len() {
|
||||
sum += nums[i];
|
||||
if k != 0 {
|
||||
sum %= k;
|
||||
}
|
||||
match map.get(&sum) {
|
||||
Some(prev) => {
|
||||
if i as i32 - *prev > 1 {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
None => {
|
||||
map.insert(sum, i as i32);
|
||||
},
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
struct Solution;
|
||||
|
||||
fn main() {
|
||||
let nums = vec![23, 2, 4, 6, 7];
|
||||
let k = 6;
|
||||
println!("{}", Solution::check_subarray_sum(nums, k));
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "good-subarrays"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "update-the-array"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
Loading…
Reference in New Issue