Compare commits

...

3 Commits

Author SHA1 Message Date
li-chx fb53c164a8 2683. 相邻值的按位异或 2025-07-31 11:47:40 +08:00
li-chx 78f001bc32 2419. 按位与最大的最长子数组 2025-07-30 10:59:42 +08:00
li-chx 99281d724c 2411. 按位或最大的最小子数组长度 2025-07-29 11:20:14 +08:00
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 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];
}
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;
}
dp.iter().filter(|x| **x == max_or ).count() as i32
a == 0 || b == 1
}
}
fn main() {
let sl = Solution::count_max_or_subsets(vec![3,2,1,5]);
println!("{}", sl);
let sl = Solution::does_valid_array_exist(vec![1,1,0]);
println!("{:?}", sl);
}