3190. Find Minimum Operations to Make All Elements Divisible by Three Easy
1/**
2 * [3190] Find Minimum Operations to Make All Elements Divisible by Three
3 *
4 * You are given an integer array nums. In one operation, you can add or subtract 1 from any element of nums.
5 * Return the minimum number of operations to make all elements of nums divisible by 3.
6 *
7 * <strong class="example">Example 1:
8 * <div class="example-block">
9 * Input: <span class="example-io">nums = [1,2,3,4]</span>
10 * Output: <span class="example-io">3</span>
11 * Explanation:
12 * All array elements can be made divisible by 3 using 3 operations:
13 *
14 * Subtract 1 from 1.
15 * Add 1 to 2.
16 * Subtract 1 from 4.
17 * </div>
18 * <strong class="example">Example 2:
19 * <div class="example-block">
20 * Input: <span class="example-io">nums = [3,6,9]</span>
21 * Output: <span class="example-io">0</span>
22 * </div>
23 *
24 * Constraints:
25 *
26 * 1 <= nums.length <= 50
27 * 1 <= nums[i] <= 50
28 *
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/find-minimum-operations-to-make-all-elements-divisible-by-three/
33// discuss: https://leetcode.com/problems/find-minimum-operations-to-make-all-elements-divisible-by-three/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38 pub fn minimum_operations(nums: Vec<i32>) -> i32 {
39 0
40 }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 #[test]
50 fn test_3190() {
51 }
52}
53
Back
© 2025 bowen.ge All Rights Reserved.