File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 2668
2668
3342|[ Find Minimum Time to Reach Last Room II] ( ./solutions/3342-find-minimum-time-to-reach-last-room-ii.js ) |Medium|
2669
2669
3343|[ Count Number of Balanced Permutations] ( ./solutions/3343-count-number-of-balanced-permutations.js ) |Hard|
2670
2670
3344|[ Maximum Sized Array] ( ./solutions/3344-maximum-sized-array.js ) |Medium|
2671
+ 3353|[ Minimum Total Operations] ( ./solutions/3353-minimum-total-operations.js ) |Easy|
2671
2672
3355|[ Zero Array Transformation I] ( ./solutions/3355-zero-array-transformation-i.js ) |Medium|
2672
2673
3356|[ Zero Array Transformation II] ( ./solutions/3356-zero-array-transformation-ii.js ) |Medium|
2673
2674
3362|[ Zero Array Transformation III] ( ./solutions/3362-zero-array-transformation-iii.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 3353. Minimum Total Operations
3
+ * https://leetcode.com/problems/minimum-total-operations/
4
+ * Difficulty: Easy
5
+ *
6
+ * Given an array of integers nums, you can perform any number of operations on this array.
7
+ *
8
+ * In each operation, you can:
9
+ * - Choose a prefix of the array.
10
+ * - Choose an integer k (which can be negative) and add k to each element in the chosen prefix.
11
+ *
12
+ * A prefix of an array is a subarray that starts from the beginning of the array and extends to
13
+ * any point within it.
14
+ *
15
+ * Return the minimum number of operations required to make all elements in arr equal.
16
+ */
17
+
18
+ /**
19
+ * @param {number[] } nums
20
+ * @return {number }
21
+ */
22
+ var minOperations = function ( nums ) {
23
+ let result = 0 ;
24
+
25
+ for ( let i = 1 ; i < nums . length ; i ++ ) {
26
+ if ( nums [ i ] !== nums [ i - 1 ] ) {
27
+ result ++ ;
28
+ }
29
+ }
30
+
31
+ return result ;
32
+ } ;
You can’t perform that action at this time.
0 commit comments