2484. Count Palindromic Subsequences Hard
1/**
2 * [2484] Count Palindromic Subsequences
3 *
4 * Given a string of digits s, return the number of palindromic subsequences of s having length 5. Since the answer may be very large, return it modulo 10^9 + 7.
5 * Note:
6 *
7 * A string is palindromic if it reads the same forward and backward.
8 * A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.
9 *
10 *
11 * <strong class="example">Example 1:
12 *
13 * Input: s = "103301"
14 * Output: 2
15 * Explanation:
16 * There are 6 possible subsequences of length 5: "10330","10331","10301","10301","13301","03301".
17 * Two of them (both equal to "10301") are palindromic.
18 *
19 * <strong class="example">Example 2:
20 *
21 * Input: s = "0000000"
22 * Output: 21
23 * Explanation: All 21 subsequences are "00000", which is palindromic.
24 *
25 * <strong class="example">Example 3:
26 *
27 * Input: s = "9999900000"
28 * Output: 2
29 * Explanation: The only two palindromic subsequences are "99999" and "00000".
30 *
31 *
32 * Constraints:
33 *
34 * 1 <= s.length <= 10^4
35 * s consists of digits.
36 *
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/count-palindromic-subsequences/
41// discuss: https://leetcode.com/problems/count-palindromic-subsequences/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46 pub fn count_palindromes(s: String) -> i32 {
47 0
48 }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56
57 #[test]
58 fn test_2484() {
59 }
60}
61
Back
© 2025 bowen.ge All Rights Reserved.