2357. Make Array Zero by Subtracting Equal Amounts Easy
1/**
2 * [2357] Make Array Zero by Subtracting Equal Amounts
3 *
4 * You are given a non-negative integer array nums. In one operation, you must:
5 *
6 * Choose a positive integer x such that x is less than or equal to the smallest non-zero element in nums.
7 * Subtract x from every positive element in nums.
8 *
9 * Return the minimum number of operations to make every element in nums equal to 0.
10 *
11 * Example 1:
12 *
13 * Input: nums = [1,5,0,3,5]
14 * Output: 3
15 * Explanation:
16 * In the first operation, choose x = 1. Now, nums = [0,4,0,2,4].
17 * In the second operation, choose x = 2. Now, nums = [0,2,0,0,2].
18 * In the third operation, choose x = 2. Now, nums = [0,0,0,0,0].
19 *
20 * Example 2:
21 *
22 * Input: nums = [0]
23 * Output: 0
24 * Explanation: Each element in nums is already 0 so no operations are needed.
25 *
26 *
27 * Constraints:
28 *
29 * 1 <= nums.length <= 100
30 * 0 <= nums[i] <= 100
31 *
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/make-array-zero-by-subtracting-equal-amounts/
36// discuss: https://leetcode.com/problems/make-array-zero-by-subtracting-equal-amounts/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41 pub fn minimum_operations(nums: Vec<i32>) -> i32 {
42 0
43 }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn test_2357() {
54 }
55}
56
Back
© 2025 bowen.ge All Rights Reserved.