We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent fc09c8c commit d6c9b4fCopy full SHA for d6c9b4f
lcof/面试题15. 二进制中1的个数/README.md
@@ -147,6 +147,22 @@ var hammingWeight = function (n) {
147
};
148
```
149
150
+#### Swift
151
+
152
+```swift
153
+class Solution {
154
+ func hammingWeight(_ n: Int) -> Int {
155
+ var n = n
156
+ var ans = 0
157
+ while n != 0 {
158
+ n &= (n - 1)
159
+ ans += 1
160
+ }
161
+ return ans
162
163
+}
164
+```
165
166
<!-- tabs:end -->
167
168
<!-- solution:end -->
lcof/面试题15. 二进制中1的个数/Solution.swift
@@ -0,0 +1,11 @@
1
2
3
4
5
6
7
8
9
10
11
0 commit comments