-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #861 from 0xff-dev/2997
Add solution and test-cases for problem 2997
- Loading branch information
Showing
3 changed files
with
46 additions
and
26 deletions.
There are no files selected for viewing
35 changes: 21 additions & 14 deletions
35
...1-3000/2997.Minimum-Number-of-Operations-to-Make-Array-XOR-Equal-to-K/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 15 additions & 2 deletions
17
...code/2901-3000/2997.Minimum-Number-of-Operations-to-Make-Array-XOR-Equal-to-K/Solution.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,18 @@ | ||
package Solution | ||
|
||
func Solution(x bool) bool { | ||
return x | ||
func Solution(nums []int, k int) int { | ||
mask := 1 | ||
ans := 0 | ||
for shift := 0; shift < 32; shift++ { | ||
cur := mask << shift | ||
kbit := k & cur | ||
xor := 0 | ||
for _, n := range nums { | ||
xor ^= (n & cur) | ||
} | ||
if xor != kbit { | ||
ans++ | ||
} | ||
} | ||
return ans | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters