题目如下: You are given an arraynumsof non-negative integers.numsis considered special if there exists a numberxsuch that there are exactlyxnumbers innumsthat are greater than or equal tox. Notice thatxdoes not have to be an element innums. Returnxif the array is special, otherwise, retur...
题目 1608. Special Array With X Elements Greater Than or Equal X 解题方法 设置x从0开始遍历到len(nums),每次循环内再遍历nums数组,统计有多少个数大于等于x记为count,如果统计的结果大于x就break此次循环。遍历数组的循环结束后判断x是否等于count,如果是就返回x,不是的话就返回-1。 时间复杂度:O(n*n) ...
You are given an array A of strings. A move onto S consists of swapping any two even indexed characters of S, or any two odd indexed characters of S. Two strings S and T are special-equivalent if after any number of moves onto S, S == T. For example, S = “zzxy” and T = ...
方法一:从后面往前找,时间复杂度O(N): classSolution {public:intspecialArray(vector<int>&nums) { sort(nums.begin(), nums.end());if(nums.size() <= nums[0])returnnums.size();for(inti=nums.size()-1; i>0; i--){if(nums.size()-i <= nums[i] &&nums.size()-i > nums[i-1])r...