|
| 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