dsa · easy
Number of Occurrences
GreyOrangeArrayBinary SearchFoundation
Sorted nums. Return how many times target appears.
Arguments
nums— the input array of integerstarget— the value you are searching for or summing to
**Example:** [1,1,2,2,2,2,3], target=2 → 4.
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