Skip to content

Commit 8016529

Browse files
committed
1987. Number of Unique Good Subsequences: RETRY
1 parent c156916 commit 8016529

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

src/solution/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,3 +1498,4 @@ mod s1982_find_array_given_subset_sums;
14981498
mod s1984_minimum_difference_between_highest_and_lowest_of_k_scores;
14991499
mod s1985_find_the_kth_largest_integer_in_the_array;
15001500
mod s1986_minimum_number_of_work_sessions_to_finish_the_tasks;
1501+
mod s1987_number_of_unique_good_subsequences;
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
*/
39+
pub 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+
46+
impl 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)]
55+
mod tests {
56+
use super::*;
57+
58+
#[test]
59+
#[ignore]
60+
fn test_1987_example_1() {
61+
let binary = "001".to_string();
62+
63+
let result = 2;
64+
65+
assert_eq!(Solution::number_of_unique_good_subsequences(binary), result);
66+
}
67+
68+
#[test]
69+
#[ignore]
70+
fn test_1987_example_2() {
71+
let binary = "11".to_string();
72+
73+
let result = 2;
74+
75+
assert_eq!(Solution::number_of_unique_good_subsequences(binary), result);
76+
}
77+
78+
#[test]
79+
#[ignore]
80+
fn test_1987_example_3() {
81+
let binary = "101".to_string();
82+
83+
let result = 5;
84+
85+
assert_eq!(Solution::number_of_unique_good_subsequences(binary), result);
86+
}
87+
}

0 commit comments

Comments
 (0)