Class Solution
java.lang.Object
g2701_2800.s2767_partition_string_into_minimum_beautiful_substrings.Solution
2767 - Partition String Into Minimum Beautiful Substrings.<p>Medium</p>
<p>Given a binary string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that each substring is <strong>beautiful</strong>.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li>It doesn’t contain leading zeros.</li>
<li>It’s the <strong>binary</strong> representation of a number that is a power of <code>5</code>.</li>
</ul>
<p>Return <em>the <strong>minimum</strong> number of substrings in such partition.</em> If it is impossible to partition the string <code>s</code> into beautiful substrings, return <code>-1</code>.</p>
<p>A <strong>substring</strong> is a contiguous sequence of characters in a string.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> s = “1011”</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong> We can paritition the given string into [“101”, “1”].</p>
<ul>
<li>The string “101” does not contain leading zeros and is the binary representation of integer 5<sup>1</sup> = 5.</li>
<li>The string “1” does not contain leading zeros and is the binary representation of integer 5<sup>0</sup> = 1.</li>
</ul>
<p>It can be shown that 2 is the minimum number of beautiful substrings that s can be partitioned into.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> s = “111”</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong> We can paritition the given string into [“1”, “1”, “1”].</p>
<ul>
<li>The string “1” does not contain leading zeros and is the binary representation of integer 5<sup>0</sup> = 1.</li>
</ul>
<p>It can be shown that 3 is the minimum number of beautiful substrings that s can be partitioned into.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> s = “0”</p>
<p><strong>Output:</strong> -1</p>
<p><strong>Explanation:</strong> We can not partition the given string into beautiful substrings.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= s.length <= 15</code></li>
<li><code>s[i]</code> is either <code>'0'</code> or <code>'1'</code>.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minimumBeautifulSubstrings
-