dsa · easy
Number of Occurrences
Non-decreasing 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.
Example
`` Input: [1,1,2,2,2,2,3] 2 Output: 4 ``
Constraints
0 <= nums.length <= 10^5 nums is sorted in non-decreasing order 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