Skip to content

Commit

Permalink
Create 2009.Minimum-Number-of-Operations-to-Make-Array-Continuous.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
wisdompeak authored Sep 19, 2021
1 parent 4081185 commit 0cdf6b5
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Solution {
public:
int minOperations(vector<int>& nums)
{
int N = nums.size();
unordered_set<int>st(nums.begin(), nums.end());
vector<int>arr(st.begin(), st.end());
sort(arr.begin(), arr.end());

int j = 0;
int ret = INT_MAX;
for (int i=0; i<arr.size(); i++)
{
while (j<arr.size() && arr[j]-arr[i]+1<=N)
{
ret = min(ret, N-(j-i+1));
j++;
}
}
return ret;
}
};

0 comments on commit 0cdf6b5

Please sign in to comment.