Leetcode 3375 | Minimum Operations to Make Array Values Equal to K | Java Solution | C++

preview_player
Показать описание
#leetcodepotd #data #dsa
#dsaleetcode
#leetcodetoday
#coding
#programming
#java
#cpp
#leetcodepotd
#leetcodedaily
#Minimum Operations to Make Array Values Equal to K
#leetcode3375
Рекомендации по теме
Комментарии
Автор

C++ Code here-
class Solution {
public:
int minOperations(vector<int>& nums, int k) {
int n = nums.size();
int ops = 0;
unordered_set<int> hm;
for (int i = 0; i < n; i++) {
if (hm.find(nums[i]) == hm.end() && nums[i] > k) {
hm.insert(nums[i]);
ops++;
} else if (nums[i] < k) {
return -1;
}
}
return ops;
}
};

CodewithoutComplexity-bj
welcome to shbcf.ru