java.lang.Object
g2701_2800.s2767_partition_string_into_minimum_beautiful_substrings.Solution

public class Solution extends Object
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&rsquo;t contain leading zeros.</li> <li>It&rsquo;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 = &ldquo;1011&rdquo;</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> We can paritition the given string into [&ldquo;101&rdquo;, &ldquo;1&rdquo;].</p> <ul> <li>The string &ldquo;101&rdquo; does not contain leading zeros and is the binary representation of integer 5<sup>1</sup> = 5.</li> <li>The string &ldquo;1&rdquo; 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 = &ldquo;111&rdquo;</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong> We can paritition the given string into [&ldquo;1&rdquo;, &ldquo;1&rdquo;, &ldquo;1&rdquo;].</p> <ul> <li>The string &ldquo;1&rdquo; 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 = &ldquo;0&rdquo;</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 Details

    • Solution

      public Solution()
  • Method Details

    • minimumBeautifulSubstrings

      public int minimumBeautifulSubstrings(String s)