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
blockchain
sql
react
smart-contract
typescript
solana
javascript
ethereum
css
Linux
ubuntu
next.js
jekyll
hardhat
golang
ethers
Secureum
Rust
zsh
web
wallet
vscode
truffle
rpc
notion
notes
nodejs
nextjs
mocha
html
github
git
geth
express
eslint
docker
cloudflare
Vim
DSA