Skip to content

Commit

Permalink
Add 191-Number-Of-1-Bits.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
sharansalian committed Jul 30, 2022
1 parent 52bdc09 commit 5d5444e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions kotlin/191-Number-Of-1-Bits.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package kotlin

fun hammingWeight(n: Int): Int {
var n = n
var count = 0
for (i in 0 .. 31){
if(n and 1 == 1) count++
n = n shr 1
}

return count
}

0 comments on commit 5d5444e

Please sign in to comment.