Skip to content

Commit 4da24b1

Browse files
authored
feat: add swift implementation to lcof problem: No.45 (doocs#2926)
1 parent 698f216 commit 4da24b1

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lcof/面试题45. 把数组排成最小的数/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,18 @@ public class Solution {
171171
}
172172
```
173173

174+
#### Swift
175+
176+
```swift
177+
class Solution {
178+
func minNumber(_ nums: [Int]) -> String {
179+
let sortedNums = nums.map { String($0) }
180+
.sorted { $0 + $1 < $1 + $0 }
181+
return sortedNums.joined()
182+
}
183+
}
184+
```
185+
174186
<!-- tabs:end -->
175187

176188
<!-- solution:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Solution {
2+
func minNumber(_ nums: [Int]) -> String {
3+
let sortedNums = nums.map { String($0) }
4+
.sorted { $0 + $1 < $1 + $0 }
5+
return sortedNums.joined()
6+
}
7+
}

0 commit comments

Comments
 (0)