feat: add swift implementation to lcof problem: No.40 (#2921)

This commit is contained in:
Lanre Adedara 2024-05-27 09:55:40 +01:00 committed by GitHub
parent 14496937b6
commit 4973492f6a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 0 deletions

View File

@ -208,6 +208,17 @@ public class Solution {
}
```
#### Swift
```swift
class Solution {
func getLeastNumbers(_ arr: [Int], _ k: Int) -> [Int] {
let sortedArr = arr.sorted()
return Array(sortedArr.prefix(k))
}
}
```
<!-- tabs:end -->
<!-- solution:end -->

View File

@ -0,0 +1,6 @@
class Solution {
func getLeastNumbers(_ arr: [Int], _ k: Int) -> [Int] {
let sortedArr = arr.sorted()
return Array(sortedArr.prefix(k))
}
}