diff --git "a/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/README.md" index b5a7a183bb539..3281f5b384508 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/README.md" @@ -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)) + } +} +``` + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/Solution.swift" "b/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/Solution.swift" new file mode 100644 index 0000000000000..322571fe0f216 --- /dev/null +++ "b/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/Solution.swift" @@ -0,0 +1,6 @@ +class Solution { + func getLeastNumbers(_ arr: [Int], _ k: Int) -> [Int] { + let sortedArr = arr.sorted() + return Array(sortedArr.prefix(k)) + } +} \ No newline at end of file