Skip to content

Commit 21d3216

Browse files
authoredMay 17, 2024··
feat: add swift implementation to lcof problem: No.03 (#2829)
1 parent 109c602 commit 21d3216

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed
 

‎lcof/面试题03. 数组中重复的数字/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,22 @@ class Solution {
197197
}
198198
```
199199

200+
#### Swift
201+
202+
```swift
203+
class Solution {
204+
func findRepeatNumber(_ nums: [Int]) -> Int {
205+
let sortedNums = nums.sorted()
206+
for i in 0..<sortedNums.count - 1 {
207+
if sortedNums[i] == sortedNums[i + 1] {
208+
return sortedNums[i]
209+
}
210+
}
211+
return -1
212+
}
213+
}
214+
```
215+
200216
<!-- tabs:end -->
201217

202218
<!-- solution:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
func findRepeatNumber(_ nums: [Int]) -> Int {
3+
let sortedNums = nums.sorted()
4+
for i in 0..<sortedNums.count - 1 {
5+
if sortedNums[i] == sortedNums[i + 1] {
6+
return sortedNums[i]
7+
}
8+
}
9+
return -1
10+
}
11+
}

0 commit comments

Comments
 (0)
Please sign in to comment.