java.lang.Object
g1801_1900.s1863_sum_of_all_subset_xor_totals.Solution

public class Solution extends Object
1863 - Sum of All Subset XOR Totals.<p>Easy</p> <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of <strong>all its elements</strong> , or <code>0</code> if the array is <strong>empty</strong>.</p> <ul> <li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li> </ul> <p>Given an array <code>nums</code>, return <em>the <strong>sum</strong> of all <strong>XOR totals</strong> for every <strong>subset</strong> of</em> <code>nums</code>.</p> <p><strong>Note:</strong> Subsets with the <strong>same</strong> elements should be counted <strong>multiple</strong> times.</p> <p>An array <code>a</code> is a <strong>subset</strong> of an array <code>b</code> if <code>a</code> can be obtained from <code>b</code> by deleting some (possibly zero) elements of <code>b</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [1,3]</p> <p><strong>Output:</strong> 6</p> <p><strong>Explanation:</strong> The 4 subsets of [1,3] are:</p> <ul> <li> <p>The empty subset has an XOR total of 0.</p> </li> <li> <p>[1] has an XOR total of 1.</p> </li> <li> <p>[3] has an XOR total of 3.</p> </li> <li> <p>[1,3] has an XOR total of 1 XOR 3 = 2.</p> </li> </ul> <p>0 + 1 + 3 + 2 = 6</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [5,1,6]</p> <p><strong>Output:</strong> 28</p> <p><strong>Explanation:</strong> The 8 subsets of [5,1,6] are:</p> <ul> <li> <p>The empty subset has an XOR total of 0.</p> </li> <li> <p>[5] has an XOR total of 5.</p> </li> <li> <p>[1] has an XOR total of 1.</p> </li> <li> <p>[6] has an XOR total of 6.</p> </li> <li> <p>[5,1] has an XOR total of 5 XOR 1 = 4.</p> </li> <li> <p>[5,6] has an XOR total of 5 XOR 6 = 3.</p> </li> <li> <p>[1,6] has an XOR total of 1 XOR 6 = 7.</p> </li> <li> <p>[5,1,6] has an XOR total of 5 XOR 1 XOR 6 = 2.</p> </li> </ul> <p>0 + 5 + 1 + 6 + 4 + 3 + 7 + 2 = 28</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> nums = [3,4,5,6,7,8]</p> <p><strong>Output:</strong> 480</p> <p><strong>Explanation:</strong> The sum of all XOR totals for every subset is 480.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 12</code></li> <li><code>1 <= nums[i] <= 20</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • subsetXORSum

      public int subsetXORSum(int[] nums)