Class Solution
- java.lang.Object
-
- g1701_1800.s1787_make_the_xor_of_all_segments_equal_to_zero.Solution
-
public class Solution extends Object
1787 - Make the XOR of All Segments Equal to Zero.Hard
You are given an array
numsand an integerk. The XOR of a segment[left, right]whereleft <= rightis theXORof all the elements with indices betweenleftandright, inclusive:nums[left] XOR nums[left+1] XOR ... XOR nums[right].Return the minimum number of elements to change in the array such that the
XORof all segments of sizekis equal to zero.Example 1:
Input: nums = [1,2,0,3,0], k = 1
Output: 3
Explanation: Modify the array from [1 , 2 ,0, 3 ,0] to from [0 , 0 ,0, 0 ,0].
Example 2:
Input: nums = [3,4,5,2,1,7,3,4,7], k = 3
Output: 3
Explanation: Modify the array from [3,4, 5 , 2 , 1 ,7,3,4,7] to [3,4, 7 , 3 , 4 ,7,3,4,7].
Example 3:
Input: nums = [1,2,4,1,2,5,1,2,6], k = 3
Output: 3
Explanation: Modify the array from [1,2, **4, **1,2, 5 ,1,2, 6 ] to [1,2, 3 ,1,2, 3 ,1,2, 3 ].
Constraints:
1 <= k <= nums.length <= 20000 <= nums[i] < 210
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intminChanges(int[] nums, int k)
-