# 191. Number of 1 Bits {%hackmd theme-dark %} 10001000 x 10000111 x-1 & 10000000 [191. Number of 1 Bits](https://leetcode.com/problems/number-of-1-bits/) [233. Number of Digit One](https://leetcode.com/problems/number-of-digit-one/) 11100111 -123 ```python= // -123 -> 1 (-3) -12 -> (-2) -1 -> (-1) // -121 -> 2 // &1 = %2 // int : -2^31 ~ 2^31 -1 // long long : 最小值不可以轉正 -> 判斷是否 LongLongMIN int countDigitOneOfX(long long x){ if(xx<0) xx = -xx; if(x>=0){ int ans = 0; while(x){ if(x % 10 == 1){ ans ++; } x /= 10; } }else{ int ans = 0; while(x){ if(x % 10 == -1){ // ????? ans ++; } x /= 10; } } } ``` ###### tags: `mock interview` `面試`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up