Saturday, March 4, 2023
n
is a length of numberfunc longestNiceSubarray(nums []int) int {
maxLength := 0
sum := 0
startSubArrayIndex := 0
for index := range nums {
for sum&nums[index] != 0 {
sum ^= nums[startSubArrayIndex]
startSubArrayIndex++
}
sum ^= nums[index]
maxLength = max(maxLength, index - startSubArrayIndex + 1)
}
return maxLength
}
func max(num1 int, num2 int) int {
if num1 > num2 {
return num1
}
return num2
}