Skip to content

Commit

Permalink
add sol
Browse files Browse the repository at this point in the history
  • Loading branch information
ductnn committed May 20, 2024
1 parent 64337dc commit e95d6c4
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions leetcode/1863.SumofAllSubsetXORTotals/sol.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// https://leetcode.com/problems/sum-of-all-subset-xor-totals

package main

import (
"fmt"
)

func subsetXORSum(nums []int) int {
n := len(nums)
res := 0
for i := 1; i < 1<<n; i++ {
sum := 0
for k, v := range nums {
if i>>k&1 == 1 {
sum ^= v
}
}
res += sum
}
return res
}

func main() {
nums := []int{5, 1, 6}
fmt.Println(subsetXORSum(nums))
}

0 comments on commit e95d6c4

Please sign in to comment.