File tree 2 files changed +34
-0
lines changed
2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 208
208
916|[ Word Subsets] ( ./0916-word-subsets.js ) |Medium|
209
209
922|[ Sort Array By Parity II] ( ./0922-sort-array-by-parity-ii.js ) |Easy|
210
210
925|[ Long Pressed Name] ( ./0925-long-pressed-name.js ) |Easy|
211
+ 926|[ Flip String to Monotone Increasing] ( ./0926-flip-string-to-monotone-increasing.js ) |Medium|
211
212
929|[ Unique Email Addresses] ( ./0929-unique-email-addresses.js ) |Easy|
212
213
966|[ Vowel Spellchecker] ( ./0966-vowel-spellchecker.js ) |Medium|
213
214
970|[ Powerful Integers] ( ./0970-powerful-integers.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 926. Flip String to Monotone Increasing
3
+ * https://leetcode.com/problems/flip-string-to-monotone-increasing/
4
+ * Difficulty: Medium
5
+ *
6
+ * A binary string is monotone increasing if it consists of some number of 0's
7
+ * (possibly none), followed by some number of 1's (also possibly none).
8
+ *
9
+ * You are given a binary string s. You can flip s[i] changing it from 0 to 1
10
+ * or from 1 to 0.
11
+ *
12
+ * Return the minimum number of flips to make s monotone increasing.
13
+ */
14
+
15
+ /**
16
+ * @param {string } s
17
+ * @return {number }
18
+ */
19
+ var minFlipsMonoIncr = function ( s ) {
20
+ let result = 0 ;
21
+ let count = 0 ;
22
+
23
+ for ( const str of s ) {
24
+ if ( str == '1' ) {
25
+ count ++ ;
26
+ } else if ( str == '0' && count > 0 ) {
27
+ result ++ ;
28
+ count -- ;
29
+ }
30
+ }
31
+
32
+ return result ;
33
+ } ;
You can’t perform that action at this time.
0 commit comments