-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cs
More file actions
32 lines (32 loc) · 814 Bytes
/
Solution.cs
File metadata and controls
32 lines (32 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public class Solution
{
public int CountTexts(string pressedKeys)
{
int n = pressedKeys.Length;
int[] map = new int[n];
map[0] = 1;
for (int i = 1; i < n; i++)
{
if (pressedKeys[i] == pressedKeys[i - 1])
{
int max = pressedKeys[i] == '7' || pressedKeys[i] == '9' ? 4 : 3;
map[i] = Math.Min(max, map[i - 1] + 1);
}
else
{
map[i] = 1;
}
}
int mod = (int)1e9 + 7;
int[] dp = new int[n + 1];
dp[0] = 1;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= map[i - 1]; j++)
{
dp[i] = (dp[i] + dp[i - j]) % mod;
}
}
return dp[n];
}
}