class Solution:
def specialArray(self, nums: List[int]) -> int:
def count(x):
c = 0
for e in nums:
if e >= x:
c += 1
return c
for i in range(0, len(nums) + 1):
if i == count(i):
return i
return -1
Slightly better approach
class Solution:
def specialArray(self, nums: List[int]) -> int:
# Sort nums in reverse order
nums = sorted(nums, reverse = True)
def count(x):
c = 0
for e in nums:
if e >= x:
c += 1
else:
break
return c
for i in range(0, len(nums) + 1):
if i == count(i):
return i
return -1