This commit is contained in:
kkunkka
2025-06-25 10:44:12 +08:00
parent 1b5422af0f
commit 557ebcc92f
4 changed files with 60 additions and 1 deletions

View File

@@ -0,0 +1,11 @@
package com.dota.bit._2317;
class Solution {
public int maximumXOR(int[] nums) {
var x = 0;
for (int num : nums) {
x |= num;
}
return x;
}
}

View File

@@ -0,0 +1,11 @@
package com.dota.bit._2527;
class Solution {
public int xorBeauty(int[] nums) {
int x = 0;
for (int num : nums) {
x ^= num;
}
return x;
}
}

View File

@@ -0,0 +1,31 @@
package com.dota.bit._2564;
import java.util.HashMap;
class Solution {
public int[][] substringXorQueries(String s, int[][] queries) {
var map = new HashMap<String, Integer>();
for (int i = 0; i < s.length(); i++) {
for (int j = 0; j < 30 && i+j<s.length(); j++) {
var t = s.substring(i, i+j+1);
if (!map.containsKey(t)) {
map.put(t, i);
}
}
}
var res = new int[queries.length][2];
var idx = 0;
for (int[] query : queries) {
int x = query[0] ^ query[1];
var b = Integer.toBinaryString(x);
int i = map.getOrDefault(b, -1);
if (i==-1) {
res[idx++] = new int[]{-1,-1};
} else {
res[idx++] = new int[]{i, i + b.length() - 1};
}
}
return res;
}
}

View File

@@ -2,6 +2,12 @@ package com.dota.bit._2683;
class Solution {
public boolean doesValidArrayExist(int[] derived) {
return false;
int n = derived.length;
int[] res = new int[n];
res[0] = 1;
for (int i = 1; i < derived.length; i++) {
res[i] = derived[i - 1] ^ res[i-1];
}
return (res[0]^res[n-1]) == derived[n-1];
}
}