Skip to content

Commit 0cdf6b5

Browse files
authored
Create 2009.Minimum-Number-of-Operations-to-Make-Array-Continuous.cpp
1 parent 4081185 commit 0cdf6b5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public:
3+
int minOperations(vector<int>& nums)
4+
{
5+
int N = nums.size();
6+
unordered_set<int>st(nums.begin(), nums.end());
7+
vector<int>arr(st.begin(), st.end());
8+
sort(arr.begin(), arr.end());
9+
10+
int j = 0;
11+
int ret = INT_MAX;
12+
for (int i=0; i<arr.size(); i++)
13+
{
14+
while (j<arr.size() && arr[j]-arr[i]+1<=N)
15+
{
16+
ret = min(ret, N-(j-i+1));
17+
j++;
18+
}
19+
}
20+
return ret;
21+
}
22+
};

0 commit comments

Comments
 (0)