We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 041c005 + f664af1 commit 6ac4728Copy full SHA for 6ac4728
Count Occurrences/README.markdown
@@ -25,7 +25,7 @@ In code this looks as follows:
25
func countOccurrences<T: Comparable>(of key: T, in array: [T]) -> Int {
26
var leftBoundary: Int {
27
var low = 0
28
- var high = a.count
+ var high = array.count
29
while low < high {
30
let midIndex = low + (high - low)/2
31
if a[midIndex] < key {
@@ -39,7 +39,7 @@ func countOccurrences<T: Comparable>(of key: T, in array: [T]) -> Int {
39
40
var rightBoundary: Int {
41
42
43
44
45
if a[midIndex] > key {
@@ -62,7 +62,7 @@ To test this algorithm, copy the code to a playground and then do:
62
```swift
63
let a = [ 0, 1, 1, 3, 3, 3, 3, 6, 8, 10, 11, 11 ]
64
65
-countOccurrencesOfKey(3, inArray: a) // returns 4
+countOccurrences(of: 3, in: a) // returns 4
66
```
67
68
> **Remember:** If you use your own array, make sure it is sorted first!
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments