1608-special-array-with-x-elements-greater-than-or-equal-x

DevGod
Vtuber
/** * @param {number[]} nums * @return {number} */var specialArray = function(nums) { nums.sort(function(a,b){return a-b;});
function binarySearch(nums, val){ let left = 0; let right = nums.length-1;
let index = nums.length; while(left<=right){ let mid = Math.floor( (left+right)/2);
if(nums[mid] >= val){ index = mid; right = mid-1; }else{ left = mid+1; } } return index; }
console.log(binarySearch(nums,0)); console.log(binarySearch(nums,6)); for(let I = 1; I<=nums.length; I++){ if(nums.length - binarySearch(nums,I) === I){ return I; } } return -1;};
class Solution: def get_first_greater_or_equal(self, nums, val): start = 0 end = len(nums) - 1
index = len(nums) while start <= end: mid = (start + end) // 2
if nums[mid] >= val: index = mid end = mid - 1 else: start = mid + 1
return index
def specialArray(self, nums: List[int]) -> int: print(self.get_first_greater_or_equal(nums,3)) return 5