Skip to content

Commit 831db2c

Browse files
add 1863
1 parent 2e16942 commit 831db2c

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1863|[Sum of All Subset XOR Totals](https://leetcode.com/problems/sum-of-all-subset-xor-totals/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1863.java) ||Easy|Backtracking, Recursion|
1112
|1862|[Sum of Floored Pairs](https://leetcode.com/problems/sum-of-floored-pairs/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1862.java) ||Hard|Math|
1213
|1861|[Rotating the Box](https://leetcode.com/problems/rotating-the-box/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1861.java) ||Medium|Array, Two Pointers|
1314
|1860|[Incremental Memory Leak](https://leetcode.com/problems/incremental-memory-leak/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1860.java) ||Medium|Math|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class _1863 {
7+
public static class Solution1 {
8+
public int subsetXORSum(int[] nums) {
9+
int sum = 0;
10+
List<List<Integer>> subsets = subsets(nums);
11+
for (List<Integer> subset : subsets) {
12+
int xor = 0;
13+
for (int i : subset) {
14+
xor ^= i;
15+
}
16+
sum += xor;
17+
}
18+
return sum;
19+
}
20+
21+
public List<List<Integer>> subsets(int[] nums) {
22+
List<List<Integer>> result = new ArrayList();
23+
backtracking(result, new ArrayList(), nums, 0);
24+
return result;
25+
}
26+
27+
void backtracking(List<List<Integer>> result, List<Integer> list, int[] nums, int start) {
28+
result.add(new ArrayList(list));
29+
for (int i = start; i < nums.length; i++) {
30+
list.add(nums[i]);
31+
backtracking(result, list, nums, i + 1);
32+
list.remove(list.size() - 1);
33+
}
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)