URL: https://leetcode.com/problems/minimum-operations-to-make-array-values-equal-to-k/ Signed-off-by: Matej Focko <me@mfocko.xyz>
16 lines
423 B
C#
16 lines
423 B
C#
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;
|
|
}
|
|
}
|