Skip to content

Commit 7f627a2

Browse files
Update Count Occurrences to Swift 3
1 parent 8f04475 commit 7f627a2

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

Count Occurrences/CountOccurrences.playground/Contents.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//: Playground - noun: a place where people can play
22

3-
func countOccurrencesOfKey(key: Int, inArray a: [Int]) -> Int {
3+
func countOccurrencesOfKey(_ key: Int, inArray a: [Int]) -> Int {
44
func leftBoundary() -> Int {
55
var low = 0
66
var high = a.count
@@ -53,7 +53,7 @@ func createArray() -> [Int] {
5353
}
5454
}
5555
}
56-
return a.sort(<)
56+
return a.sorted()
5757
}
5858

5959
for _ in 0..<10 {

Count Occurrences/CountOccurrences.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Counts the number of times a value appears in an array in O(lg n) time.
33
The array must be sorted from low to high.
44
*/
5-
func countOccurrencesOfKey(key: Int, inArray a: [Int]) -> Int {
5+
func countOccurrencesOfKey(_ key: Int, inArray a: [Int]) -> Int {
66
func leftBoundary() -> Int {
77
var low = 0
88
var high = a.count

Count Occurrences/README.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The trick is to use two binary searches, one to find where the `3`s start (the l
2222
In code this looks as follows:
2323

2424
```swift
25-
func countOccurrencesOfKey(key: Int, inArray a: [Int]) -> Int {
25+
func countOccurrencesOfKey(_ key: Int, inArray a: [Int]) -> Int {
2626
func leftBoundary() -> Int {
2727
var low = 0
2828
var high = a.count

0 commit comments

Comments
 (0)