Skip to content

Commit a4c0461

Browse files
authored
Create 3375. Minimum Operations to Make Array Values Equal to K (#762)
2 parents e575958 + 1c80f67 commit a4c0461

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
int minOperations(vector<int>& nums, int k) {
4+
unordered_map<int, int> hash;
5+
int res = 0;
6+
for(int i=0; i<nums.size(); i++) {
7+
if(nums[i] < k) return -1;
8+
if(!hash[nums[i]] && nums[i] != k) {
9+
hash[nums[i]] = 1;
10+
res++;
11+
}
12+
}
13+
return res;
14+
}
15+
};

0 commit comments

Comments
 (0)