mirror of https://github.com/doocs/leetcode.git
feat: add swift implementation to lcof problem: No.40 (#2921)
This commit is contained in:
parent
14496937b6
commit
4973492f6a
|
|
@ -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 -->
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
class Solution {
|
||||
func getLeastNumbers(_ arr: [Int], _ k: Int) -> [Int] {
|
||||
let sortedArr = arr.sorted()
|
||||
return Array(sortedArr.prefix(k))
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue