1 Star 0 Fork 0

catyMap/AlgorithmNote

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
subsetXORSum.go 492 Bytes
Copy Edit Raw Blame History
catyMap authored 2021-06-08 22:54 +08:00 . 添加一些背包问题
package main
import (
"fmt"
)
func subsetXORSum(nums []int) int {
n := len(nums)
res := 0
var depth func(idx int)
trace := make([]int, 0, 0)
depth = func(idx int) {
for i := idx; i < n; i++ {
trace = append(trace, nums[i])
res += xorSum(trace)
depth(i + 1)
trace = trace[:len(trace)-1]
}
}
depth(0)
return res
}
func xorSum(nums []int) int {
res := 0
for _, v := range nums {
res ^= v
}
return res
}
func main() {
fmt.Println(subsetXORSum([]int{5,1,6}))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/dogemap/algorithm-note.git
git@gitee.com:dogemap/algorithm-note.git
dogemap
algorithm-note
AlgorithmNote
dc486f96f6c1

Search