Skip to content

Bit Contribution Method

Table of Contents

477. Total Hamming Distance

1863. Sum of All Subset XOR Totals

  • LeetCode | 力扣

  • Tags: Array, Math, Backtracking, Bit Manipulation, Combinatorics, Enumeration

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

  • LeetCode | 力扣

  • Tags: Array, Hash Table, Bit Manipulation, Counting

1835. Find XOR Sum of All Pairs Bitwise AND

2505. Bitwise OR of All Subsequence Sums 👑

3153. Sum of Digit Differences of All Pairs