2784. 检查数组是否是好的

题目链接:https://leetcode.cn/problems/check-if-array-is-good/description/

执行用时:16 ms, 在所有 Swift 提交中击败了100.00% 的用户
内存消耗:13.53 MB, 在所有 Swift 提交中击败了100.00% 的用户

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Solution {
func isGood(_ nums: [Int]) -> Bool {
let n = nums.count;
var sortednums = nums.sorted()
for i in 0 ..< n - 1 {
if sortednums[i] != i + 1 {
return false;
}
}
if sortednums[n - 1] == n - 1 {
return true;
}
return false;
}
}

2784. 检查数组是否是好的
https://pisces34.github.io/2023/08/08/leetcode/2784/
发布于
2023年8月8日
许可协议