Count Occurrences in a Sorted Array
Given a non-decreasing integer array nums and an integer target, return how many times target occurs in the array. Return 0 when it is absent.
Given a non-decreasing integer array `nums` and an integer `target`, return how many times `target` occurs in the array. Return `0` when it is absent.
- `1 <= nums.length <= 10^5` - `-10^9 <= nums[i], target <= 10^9` - `nums` is sorted in non-decreasing order.
Example 1: input nums = [2,2,3,3,3,3,4], target = 3; output 4. Indices 2 through 5 contain the target.
Example 2: input nums = [1,2,4,5], target = 3; output 0. The target is absent.
Category: Binary Search. Topic: binary-search. Difficulty: Easy. Patterns: binary-search.