File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -81,6 +81,18 @@ impl Solution {
81
81
}
82
82
```
83
83
84
+ ``` swift
85
+ class Solution {
86
+ func exchangeBits (_ num : Int ) -> Int {
87
+ let oddShifted = (num & 0x55555555 ) << 1
88
+
89
+ let evenShifted = (num & 0xaaaaaaaa ) >> 1
90
+
91
+ return oddShifted | evenShifted
92
+ }
93
+ }
94
+ ```
95
+
84
96
<!-- tabs: end -->
85
97
86
98
<!-- end -->
Original file line number Diff line number Diff line change @@ -87,6 +87,18 @@ impl Solution {
87
87
}
88
88
```
89
89
90
+ ``` swift
91
+ class Solution {
92
+ func exchangeBits (_ num : Int ) -> Int {
93
+ let oddShifted = (num & 0x55555555 ) << 1
94
+
95
+ let evenShifted = (num & 0xaaaaaaaa ) >> 1
96
+
97
+ return oddShifted | evenShifted
98
+ }
99
+ }
100
+ ```
101
+
90
102
<!-- tabs: end -->
91
103
92
104
<!-- end -->
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ func exchangeBits( _ num: Int ) -> Int {
3
+ let oddShifted = ( num & 0x55555555 ) << 1
4
+
5
+ let evenShifted = ( num & 0xaaaaaaaa ) >> 1
6
+
7
+ return oddShifted | evenShifted
8
+ }
9
+ }
You can’t perform that action at this time.
0 commit comments