kk
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.dota;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Solution {
|
||||
// 1423. 可获得的最大点数
|
||||
public int maxScore(int[] cardPoints, int k) {
|
||||
@@ -60,4 +62,19 @@ public class Solution {
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class Solution2 {
|
||||
public long beautifulSubarrays(int[] nums) {
|
||||
long count = 0;
|
||||
var map = new HashMap<Integer, Integer>();
|
||||
map.put(0, 1);
|
||||
var mask = 0;
|
||||
for (int num : nums) {
|
||||
mask ^= num;
|
||||
count += map.getOrDefault(mask, 0);
|
||||
map.put(mask, map.getOrDefault(mask, 0) + 1);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user