Skip to content

Commit 169b668

Browse files
committed
2266. Count Number of Texts: RETRY
1 parent 1dfadcf commit 169b668

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

src/solution/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,3 +1715,4 @@ mod s2261_k_divisible_elements_subarrays;
17151715
mod s2262_total_appeal_of_a_string;
17161716
mod s2264_largest_3_same_digit_number_in_string;
17171717
mod s2265_count_nodes_equal_to_average_of_subtree;
1718+
mod s2266_count_number_of_texts;
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* [2266] Count Number of Texts
3+
*
4+
* Alice is texting Bob using her phone. The mapping of digits to letters is shown in the figure below.
5+
* <img alt="" src="https://assets.leetcode.com/uploads/2022/03/15/1200px-telephone-keypad2svg.png" style="width: 200px; height: 162px;" />
6+
* In order to add a letter, Alice has to press the key of the corresponding digit i times, where i is the position of the letter in the key.
7+
*
8+
* For example, to add the letter 's', Alice has to press '7' four times. Similarly, to add the letter 'k', Alice has to press '5' twice.
9+
* Note that the digits '0' and '1' do not map to any letters, so Alice does not use them.
10+
*
11+
* However, due to an error in transmission, Bob did not receive Alice's text message but received a string of pressed keys instead.
12+
*
13+
* For example, when Alice sent the message "bob", Bob received the string "2266622".
14+
*
15+
* Given a string pressedKeys representing the string received by Bob, return the total number of possible text messages Alice could have sent.
16+
* Since the answer may be very large, return it modulo 10^9 + 7.
17+
*
18+
* Example 1:
19+
*
20+
* Input: pressedKeys = "22233"
21+
* Output: 8
22+
* Explanation:
23+
* The possible text messages Alice could have sent are:
24+
* "aaadd", "abdd", "badd", "cdd", "aaae", "abe", "bae", and "ce".
25+
* Since there are 8 possible messages, we return 8.
26+
*
27+
* Example 2:
28+
*
29+
* Input: pressedKeys = "222222222222222222222222222222222222"
30+
* Output: 82876089
31+
* Explanation:
32+
* There are 2082876103 possible text messages Alice could have sent.
33+
* Since we need to return the answer modulo 10^9 + 7, we return 2082876103 % (10^9 + 7) = 82876089.
34+
*
35+
*
36+
* Constraints:
37+
*
38+
* 1 <= pressedKeys.length <= 10^5
39+
* pressedKeys only consists of digits from '2' - '9'.
40+
*
41+
*/
42+
pub struct Solution {}
43+
44+
// problem: https://leetcode.com/problems/count-number-of-texts/
45+
// discuss: https://leetcode.com/problems/count-number-of-texts/discuss/?currentPage=1&orderBy=most_votes&query=
46+
47+
// submission codes start here
48+
49+
impl Solution {
50+
pub fn count_texts(pressed_keys: String) -> i32 {
51+
0
52+
}
53+
}
54+
55+
// submission codes end
56+
57+
#[cfg(test)]
58+
mod tests {
59+
use super::*;
60+
61+
#[test]
62+
#[ignore]
63+
fn test_2266_example_1() {
64+
let pressed_keys = "22233".to_string();
65+
66+
let result = 8;
67+
68+
assert_eq!(Solution::count_texts(pressed_keys), result);
69+
}
70+
71+
#[test]
72+
#[ignore]
73+
fn test_2266_example_2() {
74+
let pressed_keys = "222222222222222222222222222222222222".to_string();
75+
76+
let result = 82876089;
77+
78+
assert_eq!(Solution::count_texts(pressed_keys), result);
79+
}
80+
}

0 commit comments

Comments
 (0)