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