Skip to content

Commit 4973492

Browse files
authored
feat: add swift implementation to lcof problem: No.40 (doocs#2921)
1 parent 1449693 commit 4973492

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lcof/面试题40. 最小的k个数/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,17 @@ public class Solution {
208208
}
209209
```
210210

211+
#### Swift
212+
213+
```swift
214+
class Solution {
215+
func getLeastNumbers(_ arr: [Int], _ k: Int) -> [Int] {
216+
let sortedArr = arr.sorted()
217+
return Array(sortedArr.prefix(k))
218+
}
219+
}
220+
```
221+
211222
<!-- tabs:end -->
212223

213224
<!-- solution:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Solution {
2+
func getLeastNumbers(_ arr: [Int], _ k: Int) -> [Int] {
3+
let sortedArr = arr.sorted()
4+
return Array(sortedArr.prefix(k))
5+
}
6+
}

0 commit comments

Comments
 (0)