dsa · easy

Number of Occurrences

GreyOrangeArrayBinary SearchFoundation

Sorted nums. Return how many times target appears.

Arguments

**Example:** [1,1,2,2,2,2,3], target=24.

Constraints

0 <= nums.length <= 10^5 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
[1,1,2,2,2,2,3]
2

Expected:
4

Example 2

Input:
[1,1,2,2,2,2,3]
4

Expected:
0

Open in the Dojo editor