1987. Number of Unique Good Subsequences Hard
1/**
2 * [1987] Number of Unique Good Subsequences
3 *
4 * You are given a binary string binary. A subsequence of binary is considered good if it is not empty and has no leading zeros (with the exception of "0").
5 * Find the number of unique good subsequences of binary.
6 *
7 * For example, if binary = "001", then all the good subsequences are ["0", "0", "1"], so the unique good subsequences are "0" and "1". Note that subsequences "00", "01", and "001" are not good because they have leading zeros.
8 *
9 * Return the number of unique good subsequences of binary. Since the answer may be very large, return it modulo 10^9 + 7.
10 * A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.
11 *
12 * Example 1:
13 *
14 * Input: binary = "001"
15 * Output: 2
16 * Explanation: The good subsequences of binary are ["0", "0", "1"].
17 * The unique good subsequences are "0" and "1".
18 *
19 * Example 2:
20 *
21 * Input: binary = "11"
22 * Output: 2
23 * Explanation: The good subsequences of binary are ["1", "1", "11"].
24 * The unique good subsequences are "1" and "11".
25 * Example 3:
26 *
27 * Input: binary = "101"
28 * Output: 5
29 * Explanation: The good subsequences of binary are ["1", "0", "1", "10", "11", "101"].
30 * The unique good subsequences are "0", "1", "10", "11", and "101".
31 *
32 *
33 * Constraints:
34 *
35 * 1 <= binary.length <= 10^5
36 * binary consists of only '0's and '1's.
37 *
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/number-of-unique-good-subsequences/
42// discuss: https://leetcode.com/problems/number-of-unique-good-subsequences/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47 pub fn number_of_unique_good_subsequences(binary: String) -> i32 {
48 0
49 }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56 use super::*;
57
58 #[test]
59 fn test_1987() {
60 }
61}
62
Back
© 2025 bowen.ge All Rights Reserved.