Skip to content

Commit c84d83e

Browse files
committed
Add solution #1529
1 parent fb498cd commit c84d83e

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,348 LeetCode solutions in JavaScript
1+
# 1,349 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1168,6 +1168,7 @@
11681168
1525|[Number of Good Ways to Split a String](./solutions/1525-number-of-good-ways-to-split-a-string.js)|Medium|
11691169
1526|[Minimum Number of Increments on Subarrays to Form a Target Array](./solutions/1526-minimum-number-of-increments-on-subarrays-to-form-a-target-array.js)|Hard|
11701170
1528|[Shuffle String](./solutions/1528-shuffle-string.js)|Easy|
1171+
1529|[Minimum Suffix Flips](./solutions/1529-minimum-suffix-flips.js)|Medium|
11711172
1534|[Count Good Triplets](./solutions/1534-count-good-triplets.js)|Easy|
11721173
1535|[Find the Winner of an Array Game](./solutions/1535-find-the-winner-of-an-array-game.js)|Medium|
11731174
1550|[Three Consecutive Odds](./solutions/1550-three-consecutive-odds.js)|Easy|
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* 1529. Minimum Suffix Flips
3+
* https://leetcode.com/problems/minimum-suffix-flips/
4+
* Difficulty: Medium
5+
*
6+
* You are given a 0-indexed binary string target of length n. You have another binary string s
7+
* of length n that is initially set to all zeros. You want to make s equal to target.
8+
*
9+
* In one operation, you can pick an index i where 0 <= i < n and flip all bits in the inclusive
10+
* range [i, n - 1]. Flip means changing '0' to '1' and '1' to '0'.
11+
*
12+
* Return the minimum number of operations needed to make s equal to target.
13+
*/
14+
15+
/**
16+
* @param {string} target
17+
* @return {number}
18+
*/
19+
var minFlips = function(target) {
20+
let current = '0';
21+
let result = 0;
22+
23+
for (const bit of target) {
24+
if (bit !== current) {
25+
result++;
26+
current = bit;
27+
}
28+
}
29+
30+
return result;
31+
};

0 commit comments

Comments
 (0)