2683. 相邻值的按位异或
This commit is contained in:
parent
78f001bc32
commit
fb53c164a8
33
src/main.rs
33
src/main.rs
|
@ -2,35 +2,18 @@ use std::cmp::max;
|
||||||
|
|
||||||
struct Solution;
|
struct Solution;
|
||||||
impl Solution {
|
impl Solution {
|
||||||
pub fn longest_subarray(nums: Vec<i32>) -> i32 {
|
pub fn does_valid_array_exist(derived: Vec<i32>) -> bool {
|
||||||
let mut ans = 0;
|
let mut a = 0;
|
||||||
let mut ans_val = 0;
|
let mut b = 1;
|
||||||
let mut last = 0;
|
for i in derived.iter() {
|
||||||
let mut count = 0;
|
a ^= i;
|
||||||
for i in 0..nums.len() {
|
b ^= i;
|
||||||
if nums[i] != last {
|
|
||||||
if ans_val < last {
|
|
||||||
ans_val = last;
|
|
||||||
ans = count;
|
|
||||||
}else if ans_val == last {
|
|
||||||
ans = max(count,ans);
|
|
||||||
}
|
|
||||||
last = nums[i];
|
|
||||||
count = 1;
|
|
||||||
} else {
|
|
||||||
count += 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ans_val < last {
|
a == 0 || b == 1
|
||||||
ans = count;
|
|
||||||
}else if ans_val == last {
|
|
||||||
ans = max(count,ans);
|
|
||||||
}
|
|
||||||
ans
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let sl = Solution::longest_subarray(vec![96317,96317,96317,96317,96317,96317,96317,96317,96317,279979]);
|
let sl = Solution::does_valid_array_exist(vec![1,1,0]);
|
||||||
println!("{:?}", sl);
|
println!("{:?}", sl);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue