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