Skip to content

Commit 5aa6e17

Browse files
authored
Downgraded from BinaryInteger to Numeric. Fixes documentation.
1 parent 1279b37 commit 5aa6e17

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

3Sum and 4Sum/3Sum.playground/Contents.swift

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ extension Collection where Element: Equatable {
33
/// Returns next index with unique value. Works only on sorted arrays.
44
///
55
/// - Parameter index: The current `Int` index.
6-
/// - Returns: The new `Int` index. Will return `nil` if new index happens to be the `endIndex` (out of bounds)
6+
/// - Returns: The new index. Will return `nil` if new index happens to be the `endIndex` (out of bounds)
77
func uniqueIndex(after index: Index) -> Index? {
88
guard index < endIndex else { return nil }
99
var index = index
@@ -13,20 +13,16 @@ extension Collection where Element: Equatable {
1313
formIndex(after: &nextIndex)
1414
}
1515

16-
if nextIndex == endIndex {
17-
return nil
18-
} else {
19-
return nextIndex
20-
}
16+
return nextIndex != endIndex ? nextIndex : nil
2117
}
2218
}
2319

2420
extension BidirectionalCollection where Element: Equatable {
2521

2622
/// Returns next index with unique value. Works only on sorted arrays.
2723
///
28-
/// - Parameter index: The current `Int` index.
29-
/// - Returns: The new `Int` index. Will return `nil` if new index happens to come before the `startIndex` (out of bounds)
24+
/// - Parameter index: The current index.
25+
/// - Returns: The new index. Will return `nil` if new index happens to come before the `startIndex` (out of bounds)
3026
func uniqueIndex(before index: Index) -> Index? {
3127
return indices[..<index].reversed().first { index -> Bool in
3228
let nextIndex = self.index(after: index)
@@ -36,7 +32,7 @@ extension BidirectionalCollection where Element: Equatable {
3632
}
3733
}
3834

39-
func threeSum<T: BidirectionalCollection>(_ collection: T, target: T.Element) -> [[T.Element]] where T.Element: BinaryInteger & Comparable {
35+
func threeSum<T: BidirectionalCollection>(_ collection: T, target: T.Element) -> [[T.Element]] where T.Element: Numeric & Comparable {
4036
let sorted = collection.sorted()
4137
var ret: [[T.Element]] = []
4238

0 commit comments

Comments
 (0)