File tree 3 files changed +60
-0
lines changed
3 files changed +60
-0
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,27 @@ func reverseBits(num int) (ans int) {
91
91
}
92
92
```
93
93
94
+ ``` swift
95
+ class Solution {
96
+ func reverseBits (_ num : Int ) -> Int {
97
+ var ans = 0
98
+ var countZeros = 0
99
+ var j = 0
100
+
101
+ for i in 0 ..< 32 {
102
+ countZeros += (num >> i & 1 ^ 1 )
103
+ while countZeros > 1 {
104
+ countZeros -= (num >> j & 1 ^ 1 )
105
+ j += 1
106
+ }
107
+ ans = max (ans, i - j + 1 )
108
+ }
109
+
110
+ return ans
111
+ }
112
+ }
113
+ ```
114
+
94
115
<!-- tabs: end -->
95
116
96
117
<!-- end -->
Original file line number Diff line number Diff line change @@ -97,6 +97,27 @@ func reverseBits(num int) (ans int) {
97
97
}
98
98
```
99
99
100
+ ``` swift
101
+ class Solution {
102
+ func reverseBits (_ num : Int ) -> Int {
103
+ var ans = 0
104
+ var countZeros = 0
105
+ var j = 0
106
+
107
+ for i in 0 ..< 32 {
108
+ countZeros += (num >> i & 1 ^ 1 )
109
+ while countZeros > 1 {
110
+ countZeros -= (num >> j & 1 ^ 1 )
111
+ j += 1
112
+ }
113
+ ans = max (ans, i - j + 1 )
114
+ }
115
+
116
+ return ans
117
+ }
118
+ }
119
+ ```
120
+
100
121
<!-- tabs: end -->
101
122
102
123
<!-- end -->
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ func reverseBits( _ num: Int ) -> Int {
3
+ var ans = 0
4
+ var countZeros = 0
5
+ var j = 0
6
+
7
+ for i in 0 ..< 32 {
8
+ countZeros += ( num >> i & 1 ^ 1 )
9
+ while countZeros > 1 {
10
+ countZeros -= ( num >> j & 1 ^ 1 )
11
+ j += 1
12
+ }
13
+ ans = max ( ans, i - j + 1 )
14
+ }
15
+
16
+ return ans
17
+ }
18
+ }
You can’t perform that action at this time.
0 commit comments