列 '0'
Sと '1'
Sは 単調増加 、それはいくつかの数で構成されている場合 '0'
、いくつかの数字が続くS(おそらく0)、 '1'
S(またおそらく0)
私たちは、文字列与えられている S
の '0'
Sと '1'
Sを、私たちはどの反転可能 '0'
に '1'
か '1'
へ '0'
。
作るためにフリップの最小数を返し S
単調に増加。
例1:
Input: "00110"
Output: 1
Explanation: We flip the last digit to get 00111.
例2:
Input: "010110"
Output: 2
Explanation: We flip to get 011111, or alternatively 000111.
例3:
Input: "00011000"
Output: 2
Explanation: We flip to get 00000000.
注意:
1 <= S.length <= 20000
S
のみで構成さ'0'
と'1'
文字。
Githubの同期住所:
https://github.com/grandyang/leetcode/issues/926
参考文献:
https://leetcode.com/problems/flip-string-to-monotone-increasing/