Skip to content

Commit 84f5d1a

Browse files
committed
Add solution #1863
1 parent 178b8a7 commit 84f5d1a

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,160 LeetCode solutions in JavaScript
1+
# 1,161 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1020,6 +1020,7 @@
10201020
1817|[Finding the Users Active Minutes](./solutions/1817-finding-the-users-active-minutes.js)|Medium|
10211021
1832|[Check if the Sentence Is Pangram](./solutions/1832-check-if-the-sentence-is-pangram.js)|Easy|
10221022
1833|[Maximum Ice Cream Bars](./solutions/1833-maximum-ice-cream-bars.js)|Medium|
1023+
1863|[Sum of All Subset XOR Totals](./solutions/1863-sum-of-all-subset-xor-totals.js)|Easy|
10231024
1880|[Check if Word Equals Summation of Two Words](./solutions/1880-check-if-word-equals-summation-of-two-words.js)|Easy|
10241025
1886|[Determine Whether Matrix Can Be Obtained By Rotation](./solutions/1886-determine-whether-matrix-can-be-obtained-by-rotation.js)|Easy|
10251026
1910|[Remove All Occurrences of a Substring](./solutions/1910-remove-all-occurrences-of-a-substring.js)|Medium|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* 1863. Sum of All Subset XOR Totals
3+
* https://leetcode.com/problems/sum-of-all-subset-xor-totals/
4+
* Difficulty: Easy
5+
*
6+
* The XOR total of an array is defined as the bitwise XOR of all its elements, or 0 if
7+
* the array is empty.
8+
*
9+
* For example, the XOR total of the array [2,5,6] is 2 XOR 5 XOR 6 = 1.
10+
* Given an array nums, return the sum of all XOR totals for every subset of nums.
11+
* Note: Subsets with the same elements should be counted multiple times.
12+
*
13+
* An array a is a subset of an array b if a can be obtained from b by deleting some (possibly
14+
* zero) elements of b.
15+
*/
16+
17+
/**
18+
* @param {number[]} nums
19+
* @return {number}
20+
*/
21+
var subsetXORSum = function(nums) {
22+
const totalSubsets = 1 << nums.length;
23+
let result = 0;
24+
25+
for (let mask = 0; mask < totalSubsets; mask++) {
26+
let currentXOR = 0;
27+
for (let i = 0; i < nums.length; i++) {
28+
if (mask & (1 << i)) {
29+
currentXOR ^= nums[i];
30+
}
31+
}
32+
result += currentXOR;
33+
}
34+
35+
return result;
36+
};

0 commit comments

Comments
 (0)