Skip to content

Latest commit

 

History

History
25 lines (20 loc) · 518 Bytes

isgood.md

File metadata and controls

25 lines (20 loc) · 518 Bytes

题目描述:

image

解决过程:

第109场双周赛t1,ac

代码:

class Solution {
public:
    bool isGood(vector<int>& nums) {
        int n = nums.size();
        int x = *max_element(nums.begin(), nums.end());
        if (x != n - 1) return false;
        sort(nums.begin(), nums.end());
        for (int i = 1; i < n - 1; ++i) {
            if (nums[i] != nums[i-1] + 1) return false;
        }
        return true;
    }
};