题解 | #数字在升序数组中出现的次数#
数字在升序数组中出现的次数
https://www.nowcoder.com/practice/70610bf967994b22bb1c26f9ae901fa2
二分法,找右边界
class Solution: def GetNumberOfK(self , data: List[int], k: int) -> int: def RightBoard(target): i, j = 0, len(data) - 1 while i <= j: m = (i + j) // 2 if data[m] <= target: i = m + 1 else: j = m - 1 return i return RightBoard(k) - RightBoard(k - 1)