---
# System prepended metadata

title: 2357. Make Array Zero by Subtracting Equal Amounts
tags: [Leetcode, Easy]

---

# 2357. Make Array Zero by Subtracting Equal Amounts
###### tags: `Leetcode` `Easy`
Link: https://leetcode.com/problems/make-array-zero-by-subtracting-equal-amounts/description/
## 思路
数出array里面有几个不是0的unique number就是答案
因为要求minimum operation数 所以每次减掉的肯定都是最小element本身
也就是每做一次operation 最小的element都会变成0
又因为相同的数字都是同增同减的 所以只要数出unique number的个数就是答案
## Code
```java=
class Solution {
    public int minimumOperations(int[] nums) {
        Set<Integer> uni = new HashSet<>();
        for(int num:nums) uni.add(num);
        if(uni.contains(0)) return uni.size()-1;
        else return uni.size();
    }
}
```