2598. Smallest Missing Non-negative Integer After Operations
题目 2598. Smallest Missing Non-negative Integer After Operations
思路分析
代码实现
class Solution {
public int findSmallestInteger(int[] nums, int value) {
int[] count = new int[value];
for(int num:nums){
int rem = (num % value + value) % value;
count[rem]++;
}
for(int i = 0;i<nums.length;i++){
int targetRem = i%value;
if(count[targetRem]>0){
count[targetRem]--;
}else{
return i;
}
}
return nums.length;
}
}
💬 评论