Go - Return bit 1 count
13 Jan 2023Go
程式碼如下:
func BitCount(x int) int {
cnt := 0
for x > 0 { // 當 x <= 0 就是完全沒 1 了
x = x & (x - 1) // 每次會不見一個 1
cnt++
}
return cnt
}
Go
程式碼如下:
func BitCount(x int) int {
cnt := 0
for x > 0 { // 當 x <= 0 就是完全沒 1 了
x = x & (x - 1) // 每次會不見一個 1
cnt++
}
return cnt
}
solidity
picoCTF
Go
ethernaut
linux
leetcode
blockchain
array
sql
react
leetcode-top-interview
medium
typescript
smart-contract
two-pointer
solana
javascript
java
ethereum
easy
css
Linux
zsh
ubuntu
next.js
jekyll
http
hardhat
golang
ethers
Secureum
Rust
web
wallet
vscode
typeorm
truffle
stack
shell
rpc
notion
notes
nodejs
nextjs
mocha
html
github
git
geth
filesystem
express
eslint
docker
cloudflare
Vim
DSA