We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 289b9ad commit 5dba61dCopy full SHA for 5dba61d
โnumber-of-1-bits/kut7728.swift
@@ -0,0 +1,10 @@
1
+///์์ ์ ์ n์ด ์ฃผ์ด์ก์ ๋,
2
+///์ด์ง ํํ์ผ๋ก setbit์ ์๋ฅผ ๋ฐํํ๋ ํจ์(ํด๋ฐ ๊ฐ์ค์น๋ผ๊ณ ๋ ํจ)๋ฅผ ์์ฑํฉ๋๋ค.
3
+///setbit์ด๋ ์ด์ง์ ์ค์์ 1์ ๊ฐ์ ๊ฐ์ง๋ ๋นํธ์ ๊ฐฏ์
4
+
5
+class Solution {
6
+ func hammingWeight(_ n: Int) -> Int {
7
+ let count = String(n, radix: 2).filter { $0 == "1" }.count
8
+ return count
9
+ }
10
+}
0 commit comments