Compare commits

..

No commits in common. "fb53c164a8eda11c1d87d4a15064e275aa0cfc48" and "d8c4583b1157193a195f646e2b54d7408e34a819" have entirely different histories.

1 changed files with 11 additions and 11 deletions

View File

@ -1,19 +1,19 @@
use std::cmp::max;
struct Solution;
impl Solution {
pub fn does_valid_array_exist(derived: Vec<i32>) -> bool {
let mut a = 0;
let mut b = 1;
for i in derived.iter() {
a ^= i;
b ^= i;
pub fn count_max_or_subsets(nums: Vec<i32>) -> i32 {
let max_or = nums.iter().fold(0, |acc, &x| acc | x);
let mut dp = vec![0;1<<nums.len()];
for i in 0..nums.len() {
for j in (1<<i)..(1<<(i+1)) {
dp[j] = dp[j - (1<<i)] | nums[i];
}
}
a == 0 || b == 1
dp.iter().filter(|x| **x == max_or ).count() as i32
}
}
fn main() {
let sl = Solution::does_valid_array_exist(vec![1,1,0]);
println!("{:?}", sl);
let sl = Solution::count_max_or_subsets(vec![3,2,1,5]);
println!("{}", sl);
}