You are given a sorted array of integers nums that may contain duplicates, and a target integer target, find the number of occurrences of the target in the array.
Your solution should be more efficient than a linear scan.
nums = [2, 5, 5, 5, 6, 8, 9]
target = 5
3
The number 5 appears 3 times in the array.
nums = [1, 2, 3, 5, 6]
target = 4
0
The number 4 is not present in the array.
nums = [10]
target = 10
1
The number 10 appears once.
nums = [2, 5, 5, 5, 6, 8, 9]
target = 5
3