Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 501fffb

Browse files
authoredApr 5, 2025··
Create 1863_Sum_of_All_Subset_XOR_Totals.java
1 parent 98d2dfd commit 501fffb

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
 
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Problem Number: 1863.
2+
3+
// Sum of All Subset XOR totals.
4+
5+
class Solution {
6+
public int subsetXORSum(int[] nums) {
7+
return dfs(nums, 0, 0);
8+
}
9+
10+
private int dfs(int[] nums, int i, int xors) {
11+
if (i == nums.length)
12+
return xors;
13+
14+
final int x = dfs(nums, i + 1, xors);
15+
final int y = dfs(nums, i + 1, nums[i] ^ xors);
16+
return x + y;
17+
}
18+
}

0 commit comments

Comments
 (0)
Please sign in to comment.