20240306 Finished

This commit is contained in:
jackfiled 2024-03-06 09:58:10 +08:00
parent b43b547ff9
commit 59e9219040
2 changed files with 45 additions and 1 deletions

View File

@ -65,3 +65,4 @@ mod p2368_reachable_nodes_with_restrictions;
mod p225_implement_stack_using_queues; mod p225_implement_stack_using_queues;
mod p232_implement_queue_using_stacks; mod p232_implement_queue_using_stacks;
mod p1976_number_of_ways_to_arrive_at_destination; mod p1976_number_of_ways_to_arrive_at_destination;
mod p2917_find_the_k_or_of_an_array;

View File

@ -0,0 +1,43 @@
/**
* [2917] Find the K-or of an Array
*/
pub struct Solution {}
// submission codes start here
impl Solution {
pub fn find_k_or(nums: Vec<i32>, k: i32) -> i32 {
let mut result = 0;
for i in 0..32 {
let mut count = 0;
let x = 1 << i;
for num in &nums {
if *num & x == x {
count += 1;
}
}
if count >= k {
dbg!(x);
result += x;
}
}
result
}
}
// submission codes end
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_2917() {
assert_eq!(9, Solution::find_k_or(vec![7,12,9,8,9,15], 4));
}
}