Skip to content

Commit 06c0906

Browse files
committed
Add solution #3353
1 parent 527ddc2 commit 06c0906

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2668,6 +2668,7 @@
26682668
3342|[Find Minimum Time to Reach Last Room II](./solutions/3342-find-minimum-time-to-reach-last-room-ii.js)|Medium|
26692669
3343|[Count Number of Balanced Permutations](./solutions/3343-count-number-of-balanced-permutations.js)|Hard|
26702670
3344|[Maximum Sized Array](./solutions/3344-maximum-sized-array.js)|Medium|
2671+
3353|[Minimum Total Operations](./solutions/3353-minimum-total-operations.js)|Easy|
26712672
3355|[Zero Array Transformation I](./solutions/3355-zero-array-transformation-i.js)|Medium|
26722673
3356|[Zero Array Transformation II](./solutions/3356-zero-array-transformation-ii.js)|Medium|
26732674
3362|[Zero Array Transformation III](./solutions/3362-zero-array-transformation-iii.js)|Medium|
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy