20240306 Finished
This commit is contained in:
parent
b43b547ff9
commit
59e9219040
|
@ -64,4 +64,5 @@ mod p2369_check_if_there_is_a_valid_partition_for_the_array;
|
||||||
mod p2368_reachable_nodes_with_restrictions;
|
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;
|
43
src/problem/p2917_find_the_k_or_of_an_array.rs
Normal file
43
src/problem/p2917_find_the_k_or_of_an_array.rs
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user