2767. Partition String Into Minimum Beautiful Substrings Medium
1/**
2 * [2767] Partition String Into Minimum Beautiful Substrings
3 *
4 * Given a binary string s, partition the string into one or more substrings such that each substring is beautiful.
5 * A string is beautiful if:
6 *
7 * It doesn't contain leading zeros.
8 * It's the binary representation of a number that is a power of 5.
9 *
10 * Return the minimum number of substrings in such partition. If it is impossible to partition the string s into beautiful substrings, return -1.
11 * A substring is a contiguous sequence of characters in a string.
12 *
13 * <strong class="example">Example 1:
14 *
15 * Input: s = "1011"
16 * Output: 2
17 * Explanation: We can paritition the given string into ["101", "1"].
18 * - The string "101" does not contain leading zeros and is the binary representation of integer 5^1 = 5.
19 * - The string "1" does not contain leading zeros and is the binary representation of integer 5^0 = 1.
20 * It can be shown that 2 is the minimum number of beautiful substrings that s can be partitioned into.
21 *
22 * <strong class="example">Example 2:
23 *
24 * Input: s = "111"
25 * Output: 3
26 * Explanation: We can paritition the given string into ["1", "1", "1"].
27 * - The string "1" does not contain leading zeros and is the binary representation of integer 5^0 = 1.
28 * It can be shown that 3 is the minimum number of beautiful substrings that s can be partitioned into.
29 *
30 * <strong class="example">Example 3:
31 *
32 * Input: s = "0"
33 * Output: -1
34 * Explanation: We can not partition the given string into beautiful substrings.
35 *
36 *
37 * Constraints:
38 *
39 * 1 <= s.length <= 15
40 * s[i] is either '0' or '1'.
41 *
42 */
43pub struct Solution {}
44
45// problem: https://leetcode.com/problems/partition-string-into-minimum-beautiful-substrings/
46// discuss: https://leetcode.com/problems/partition-string-into-minimum-beautiful-substrings/discuss/?currentPage=1&orderBy=most_votes&query=
47
48// submission codes start here
49
50impl Solution {
51 pub fn minimum_beautiful_substrings(s: String) -> i32 {
52 0
53 }
54}
55
56// submission codes end
57
58#[cfg(test)]
59mod tests {
60 use super::*;
61
62 #[test]
63 fn test_2767() {
64 }
65}
66
Back
© 2025 bowen.ge All Rights Reserved.