From e0be1230eb06804c89d3c1c87e746059174d9a5d Mon Sep 17 00:00:00 2001 From: CyC2018 Date: Wed, 28 Oct 2026 22:51:21 +0800 Subject: [PATCH] =?UTF-8?q?Update=2053.=20=E6=95=B0=E5=AD=97=E5=9C=A8?= =?UTF-8?q?=E6=8E=92=E5=BA=8F=E6=95=B0=E7=BB=84=E4=B8=AD=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E7=9A=84=E6=AC=A1=E6=95=B0.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 示例代码块的语言标注改为 text,第一人称改为客观陈述。 --- notes/53. 数字在排序数组中出现的次数.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notes/53. 数字在排序数组中出现的次数.md b/notes/53. 数字在排序数组中出现的次数.md index 580507b6..ed08922b 100644 --- a/notes/53. 数字在排序数组中出现的次数.md +++ b/notes/53. 数字在排序数组中出现的次数.md @@ -6,7 +6,7 @@ ## 题目描述 -```html +```text Input: nums = 1, 2, 3, 3, 3, 3, 4, 6 K = 3 @@ -82,4 +82,4 @@ private int binarySearch(int[] nums, int target) { nums = [2,2], k = 2 ``` -如果 h 的取值为 nums.length - 1,那么在查找最后一个位置时,binarySearch(nums, k + 1) - 1 = 1 - 1 = 0。这是因为 binarySearch 只会返回 [0, nums.length - 1] 范围的值,对于 binarySearch([2,2], 3) ,我们希望返回 3 插入 nums 中的位置,也就是数组最后一个位置再往后一个位置,即 nums.length。所以我们需要将 h 取值为 nums.length,从而使得 binarySearch 返回的区间更大,能够覆盖 k 大于 nums 最后一个元素的情况。 +如果 h 的取值为 nums.length - 1,那么在查找最后一个位置时,binarySearch(nums, k + 1) - 1 = 1 - 1 = 0。这是因为 binarySearch 只会返回 [0, nums.length - 1] 范围的值,而 binarySearch([2,2], 3) 应该返回 3 插入 nums 中的位置,也就是数组最后一个位置再往后一个位置,即 nums.length。所以需要将 h 取值为 nums.length,从而使得 binarySearch 返回的区间更大,能够覆盖 k 大于 nums 最后一个元素的情况。