Skip to content

Commit c20b543

Browse files
authored
Create 2598.Smallest-Missing-Non-negative-Integer-After-Operations.cpp
1 parent 5042c73 commit c20b543

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution {
2+
public:
3+
int findSmallestInteger(vector<int>& nums, int value)
4+
{
5+
vector<int>count(value);
6+
7+
for (int& x: nums)
8+
{
9+
x = ((x%value)+value) % value;
10+
count[x] += 1;
11+
}
12+
13+
int min_count = INT_MAX;
14+
int k;
15+
16+
for (int i=0; i<value; i++)
17+
{
18+
if (count[i]<min_count)
19+
{
20+
min_count = count[i];
21+
k = i;
22+
}
23+
}
24+
25+
return min_count*value + k;
26+
}
27+
};

0 commit comments

Comments
 (0)