This commit is contained in:
kkunkka
2025-06-27 12:16:31 +08:00
parent 557ebcc92f
commit ec98ce5b31
4 changed files with 90 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
package com.dota.bit._1318;
class Solution {
public int minFlips(int a, int b, int c) {
var sum = 0;
while (a + b + c != 0) {
var ta = a & 1;
var tb = b & 1;
var tc = c & 1;
if ((ta | tb) != tc) {
if ((ta | tb) == 0) {
sum++;
} else {
sum = sum + ta + tb;
}
}
a >>= 1;
b >>= 1;
c >>= 1;
}
return sum;
}
}

View File

@@ -0,0 +1,21 @@
package com.dota.bit._1734;
class Solution {
public int[] decode(int[] encoded) {
int n = encoded.length + 1;
int[] res = new int[n];
int x = 0;
for (int i = 0; i < n - 1; i += 2) {
x ^= encoded[i];
}
for (int i = 1; i <= n; i++) {
x ^= i;
}
res[n - 1] = x;
for (int i = n - 2; i >= 0; i--) {
res[i] = res[i + 1] ^ encoded[i];
}
return res;
}
}

View File

@@ -0,0 +1,34 @@
package com.dota.bit._2419;
class Solution {
public static void main(String[] args) {
new Solution().longestSubarray(new int[]{311155, 311155, 311155, 311155, 311155, 311155, 311155, 311155, 201191, 311155});
}
public int longestSubarray(int[] nums) {
int max = 1;
int maxLen = 1;
int and = nums[0];
int len = 0;
for (int num : nums) {
int t = and & num;
if (t < and || t < num) {
and = num;
t = num;
len = 1;
} else {
and = t;
len++;
}
if (t > max) {
max = t;
maxLen = len;
}
if (t == max && len > maxLen) {
maxLen = len;
}
}
return maxLen;
}
}

View File

@@ -0,0 +1,11 @@
package com.dota.bit._2980;
class Solution {
public boolean hasTrailingZeros(int[] nums) {
int sum = 0;
for (int num : nums) {
if ((num & 1) == 0) sum++;
}
return sum>1;
}
}