5531. 特殊数组的特征值

5531. 特殊数组的特征值

传送门

传送门

题意

结题思路

# 思路1:
# 遍历数组,模拟判断。
class Solution(object):
    def specialArray(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        len1 = len(nums)
        for i in range(1, len1+1):
            count = 0
            # 有几个元素大于或者等于nums[i]
            for j in range(len1):
                if(nums[j] >= i):
                    count += 1
            if(count == i):
                return i
        return -1

猜你喜欢

转载自blog.csdn.net/qq_40092110/article/details/108921877
今日推荐