package
Version:
v0.0.0-...-632ac27
Opens a new window with list of versions in this module.
Published: Jan 15, 2023
License: GPL-3.0
Opens a new window with license information.
Imports: 0
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
¶
Test
$ go test -v
=== RUN TestXorProduct
--- PASS: TestXorProduct (0.00s)
PASS
ok github.com/ZhengjunHUO/leetcode/extra 0.092s
Benchmark. compare 2 methods
$ go test -bench . -benchmem
goos: darwin
goarch: arm64
pkg: github.com/ZhengjunHUO/leetcode/extra
BenchmarkXorproduct-8 1000000000 0.3149 ns/op 0 B/op 0 allocs/op
BenchmarkXorProductBF-8 38329 31300 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/ZhengjunHUO/leetcode/extra 1.968s
Documentation
¶
because:
wanted = M ^ (M+1) ^ ... ^ (N-1) ^ N
prodFromZeroToX(N) = (0 ^ 1 ^ ... ^ M-1) ^ (M ^ M+1 ^ ... ^ N-1 ^ N)
= prodFromZeroToX(M-1) ^ wanted
then XOR prodFromZeroToX(M-1) in both side we have:
wanted = prodFromZeroToX(N) ^ prodFromZeroToX(M-1)
Source Files
¶
Click to show internal directories.
Click to hide internal directories.