LeetCode/cs/minimum-operations-to-make-array-values-equal-to-k.cs

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;
}
}