Re: [闲聊] 每日leetcode

楼主: oin1104 (是oin的说)   2024-05-27 11:24:53
※ 引述 《sustainer123 (caster)》 之铭言:
:  
:  
: https://reurl.cc/gGYKGL
:  
: 1608. Special Array With X Elements Greater Than or Equal X
:  
: 给你一数列 此数列只有非负整数 假设有一整数x 数列中恰巧有x个元素大于等于x
:  
: 请回传x 假设无x 则回传-1
:  
: x不必是存在于数列的元素
:  
: Example 1:
:  
: Input: nums = [3,5]
: Output: 2
: Explanation: There are 2 values (3 and 5) that are greater than or equal to 2.
: Example 2:
:  
思路:
排序 数数字
然后看数到的地方跟>=res的数量一不一样
就可以知道要不要回传-1了
屁眼
class Solution {
public:
int specialArray(vector<int>& nums)
{
int res = 0;
int len = nums.size();
sort(nums.begin(),nums.end());
for(int i = len-1 ; i >= 0 ; i
作者: sustainer123 (caster)   2024-05-27 11:40:00
大师
作者: JIWP (JIWP)   2024-05-27 13:41:00
大师

Links booklink

Contact Us: admin [ a t ] ucptt.com