Leetcode 1608. 特殊数组的特征值(DAY 175)---- 二分算法学习期
作者:互联网
文章目录
原题题目
代码实现(首刷自解)
class Solution {
public:
int specialArray(vector<int>& nums) {
int max_x = nums.size(),ret = -1,num = 0,pos = 0;
sort(nums.begin(),nums.end());
while(num <= max_x)
{
while(pos < max_x && num > nums[pos]) ++pos;
if(nums.size() - pos <= num)
{
if(nums.size() - pos == num) ret = num;
break;
}
++num;
}
return ret;
}
};
标签:1608,nums,原题,pos,ret,----,num,Leetcode,size 来源: https://blog.csdn.net/qq_37500516/article/details/120486450