每日一题做题记录,参考官方和三叶的题解
- class Solution {
- public int specialArray(int[] nums) {
- Arrays.sort(nums);
- int n = nums.length;
- for (int x = 0; x <= nums[n - 1]; x++) { // 枚举
- int l = 0, r = n -1 ;
- while (l < r) { // 二分
- int m = l + r >> 1;
- if (nums[m] >= x)
- r = m;
- else
- l = m + 1;
- }
- if (nums[