title | date | draft | tags | categories | |||
---|---|---|---|---|---|---|---|
Algorithm4 Java Solution 1.4.11 |
2019-08-06 15:54:00 +0800 |
false |
|
|
Add an instance method howMany() to StaticSETofInts (page 99) that finds the number of occurrences of a given key in time proportional to log N in the worst case.
find the minimum index key occurs in the array, then find the maximum index.
if key is in the array
the number of occurrences = max_index - min_index + 1
else
the number of occurrences = 0
code: