Skip to content

Commit 4261a9d

Browse files
committed
Add solution #3190
1 parent 1c392a9 commit 4261a9d

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2674,6 +2674,7 @@
26742674
3183|[The Number of Ways to Make the Sum](./solutions/3183-the-number-of-ways-to-make-the-sum.js)|Medium|
26752675
3186|[Maximum Total Damage With Spell Casting](./solutions/3186-maximum-total-damage-with-spell-casting.js)|Medium|
26762676
3189|[Minimum Moves to Get a Peaceful Board](./solutions/3189-minimum-moves-to-get-a-peaceful-board.js)|Medium|
2677+
3190|[Find Minimum Operations to Make All Elements Divisible by Three](./solutions/3190-find-minimum-operations-to-make-all-elements-divisible-by-three.js)|Easy|
26772678
3191|[Minimum Operations to Make Binary Array Elements Equal to One I](./solutions/3191-minimum-operations-to-make-binary-array-elements-equal-to-one-i.js)|Medium|
26782679
3195|[Find the Minimum Area to Cover All Ones I](./solutions/3195-find-the-minimum-area-to-cover-all-ones-i.js)|Medium|
26792680
3197|[Find the Minimum Area to Cover All Ones II](./solutions/3197-find-the-minimum-area-to-cover-all-ones-ii.js)|Hard|
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* 3190. Find Minimum Operations to Make All Elements Divisible by Three
3+
* https://leetcode.com/problems/find-minimum-operations-to-make-all-elements-divisible-by-three/
4+
* Difficulty: Easy
5+
*
6+
* You are given an integer array nums. In one operation, you can add or subtract 1 from any
7+
* element of nums.
8+
*
9+
* Return the minimum number of operations to make all elements of nums divisible by 3.
10+
*/
11+
12+
/**
13+
* @param {number[]} nums
14+
* @return {number}
15+
*/
16+
var minimumOperations = function(nums) {
17+
return nums.reduce((operations, num) => {
18+
const remainder = num % 3;
19+
return operations + Math.min(remainder, 3 - remainder);
20+
}, 0);
21+
};

0 commit comments

Comments
 (0)