Skip to content

Commit ace34c0

Browse files
authored
feat: add swift implementation to lcci problem: No.16.07 (doocs#2730)
1 parent dbec400 commit ace34c0

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

lcci/16.07.Maximum/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ function maximum(a: number, b: number): number {
6464
}
6565
```
6666

67+
```swift
68+
class Solution {
69+
func maximum(_ a: Int, _ b: Int) -> Int {
70+
let diff = Int64(a) - Int64(b)
71+
let k = Int((diff >> 63) & 1)
72+
return a * (k ^ 1) + b * k
73+
}
74+
}
75+
```
76+
6777
<!-- tabs:end -->
6878

6979
<!-- end -->

lcci/16.07.Maximum/README_EN.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ function maximum(a: number, b: number): number {
6666
}
6767
```
6868

69+
```swift
70+
class Solution {
71+
func maximum(_ a: Int, _ b: Int) -> Int {
72+
let diff = Int64(a) - Int64(b)
73+
let k = Int((diff >> 63) & 1)
74+
return a * (k ^ 1) + b * k
75+
}
76+
}
77+
```
78+
6979
<!-- tabs:end -->
7080

7181
<!-- end -->

lcci/16.07.Maximum/Solution.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Solution {
2+
func maximum(_ a: Int, _ b: Int) -> Int {
3+
let diff = Int64(a) - Int64(b)
4+
let k = Int((diff >> 63) & 1)
5+
return a * (k ^ 1) + b * k
6+
}
7+
}

0 commit comments

Comments
 (0)