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
sql
react
leetcode-top-interview
array
medium
typescript
smart-contract
solana
javascript
java
ethereum
easy
css
Linux
zsh
ubuntu
two-pointer
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
express
eslint
docker
cloudflare
Vim
DSA