cs: add «3375. Minimum Operations to Make Array Values Equal to K»
URL: https://leetcode.com/problems/minimum-operations-to-make-array-values-equal-to-k/ Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
e95583b334
commit
9754709bd4
1 changed files with 16 additions and 0 deletions
16
cs/minimum-operations-to-make-array-values-equal-to-k.cs
Normal file
16
cs/minimum-operations-to-make-array-values-equal-to-k.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
public class Solution {
|
||||
public int MinOperations(int[] nums, int k) {
|
||||
var toUse = new HashSet<int>();
|
||||
foreach (var x in nums) {
|
||||
if (x < k) {
|
||||
// can't use any number of operations
|
||||
return -1;
|
||||
} else if (x > k) {
|
||||
// gotta use it at least once
|
||||
toUse.Add(x);
|
||||
}
|
||||
}
|
||||
|
||||
return toUse.Count;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue