Compare commits
3 Commits
d8c4583b11
...
fb53c164a8
Author | SHA1 | Date |
---|---|---|
|
fb53c164a8 | |
|
78f001bc32 | |
|
99281d724c |
22
src/main.rs
22
src/main.rs
|
@ -1,19 +1,19 @@
|
||||||
|
use std::cmp::max;
|
||||||
|
|
||||||
struct Solution;
|
struct Solution;
|
||||||
impl Solution {
|
impl Solution {
|
||||||
pub fn count_max_or_subsets(nums: Vec<i32>) -> i32 {
|
pub fn does_valid_array_exist(derived: Vec<i32>) -> bool {
|
||||||
let max_or = nums.iter().fold(0, |acc, &x| acc | x);
|
let mut a = 0;
|
||||||
let mut dp = vec![0;1<<nums.len()];
|
let mut b = 1;
|
||||||
for i in 0..nums.len() {
|
for i in derived.iter() {
|
||||||
for j in (1<<i)..(1<<(i+1)) {
|
a ^= i;
|
||||||
dp[j] = dp[j - (1<<i)] | nums[i];
|
b ^= i;
|
||||||
}
|
}
|
||||||
}
|
a == 0 || b == 1
|
||||||
dp.iter().filter(|x| **x == max_or ).count() as i32
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let sl = Solution::count_max_or_subsets(vec![3,2,1,5]);
|
let sl = Solution::does_valid_array_exist(vec![1,1,0]);
|
||||||
println!("{}", sl);
|
println!("{:?}", sl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue