Skip to content

Bit Contribution Method

Table of Contents

477. Total Hamming Distance

1863. Sum of All Subset XOR Totals

  • LeetCode | LeetCode CH (Easy)

  • Tags: array, math, backtracking, bit manipulation, combinatorics, enumeration

1863. Sum of All Subset XOR Totals - Python Solution
from functools import reduce
from operator import or_
from typing import List


def subsetXORSum(nums: List[int]) -> int:
    return reduce(or_, nums) << (len(nums) - 1)


if __name__ == "__main__":
    nums = [5, 1, 6]
    print(subsetXORSum(nums))  # 28

2425. Bitwise XOR of All Pairings

2275. Largest Combination With Bitwise AND Greater Than Zero

1835. Find XOR Sum of All Pairs Bitwise AND

2505. Bitwise OR of All Subsequence Sums

3153. Sum of Digit Differences of All Pairs

Comments