53-1

        public int Search(int[] nums, int target) {
            if (nums.Length == 0) return 0;
            //5, 7, 7, 8, 8, 10
            //根据两分法找到顺序数组中10的下标 减去 数组中7的下标 
            return helper(nums, target) - helper(nums, target - 1);
        }

        public int helper(int[] nums, int target) {
            int l = 0, r = nums.Length-1;
            while (l <= r) {
                int m = (l + r) / 2;
                if (nums[m] <= target) l = m + 1;
                else r = m - 1;
            }
            return l;
        }
上一篇:7-53 两个有序序列的中位数 (25 分)


下一篇:概率统计Python计算(53)单个正态总体方差单侧假设的卡方检验