Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6f4775d

Browse files
Merge pull request #872 from Priyanka-/master
Kth Largest Element: updated to use Int.random API which has been int...
2 parents 791cc66 + 7405c64 commit 6f4775d

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

‎Kth Largest Element/kthLargest.playground/Sources/kthLargest.swift‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ public func kthLargest(_ a: [Int], _ k: Int) -> Int? {
1616

1717
// MARK: - Randomized selection
1818

19-
/* Returns a random integer in the range min...max, inclusive. */
20-
public func random(min: Int, max: Int) -> Int {
21-
assert(min < max)
22-
return min + Int(arc4random_uniform(UInt32(max - min + 1)))
23-
}
24-
2519
/*
2620
Returns the i-th smallest element from the array.
2721

@@ -39,7 +33,7 @@ public func randomizedSelect<T: Comparable>(_ array: [T], order k: Int) -> T {
3933
var a = array
4034

4135
func randomPivot<T: Comparable>(_ a: inout [T], _ low: Int, _ high: Int) -> T {
42-
let pivotIndex = random(min: low, max:high)
36+
let pivotIndex = Int.random(in: low...high)
4337
a.swapAt(pivotIndex, high)
4438
return a[high]
4539
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /