mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-14 01:49:41 +01:00
18 lines
396 B
Kotlin
18 lines
396 B
Kotlin
class Solution {
|
|
private fun xorSum(
|
|
nums: IntArray,
|
|
i: Int,
|
|
sum: Int,
|
|
): Int {
|
|
if (i == nums.size) {
|
|
return sum
|
|
}
|
|
|
|
val including = xorSum(nums, i + 1, sum xor nums[i])
|
|
val excluding = xorSum(nums, i + 1, sum)
|
|
|
|
return including + excluding
|
|
}
|
|
|
|
fun subsetXORSum(nums: IntArray): Int = xorSum(nums, 0, 0)
|
|
}
|