1863. Sum of All Subset XOR Totals - Easy

前往題目

思路

  1. Recursion把所有subset都找到並計算

Code

class Solution {
    public int subsetXORSum(int[] nums) {
        return dfs(nums, 0, 0);
    }

    private int dfs(int[] nums, int index, int total) {
        // Reach the end
        if (index == nums.length) return total;

        // Include or not, to process all the subsets
        int includeI = dfs(nums, index + 1, total ^ nums[index]);
        int notIncludeI = dfs(nums, index + 1, total);

        return includeI + notIncludeI;
    }
}

1863. Sum of All Subset XOR Totals - Easy
https://f88083.github.io/2025/04/05/1863-Sum-of-All-Subset-XOR-Totals-Easy/
作者
Simon Lai
發布於
2025年4月5日
許可協議