Skip to content

Commit 4d32dfa

Browse files
committed
Runtime: 134 ms (Top 52.17%) | Memory: 48.8 MB (Top 91.30%)
1 parent 1c5fe00 commit 4d32dfa

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1+
// Runtime: 134 ms (Top 52.17%) | Memory: 48.8 MB (Top 91.30%)
12
var countTexts = function(pressedKeys) {
23
const MOD = 1e9 + 7;
34
const n = pressedKeys.length;
45
const dp = new Array(n + 1).fill(0);
5-
6+
67
dp[0] = 1;
7-
8+
89
let lastChar = "";
910
let repeatCount = 0;
10-
11+
1112
for (let i = 1; i <= n; ++i) {
1213
const currChar = pressedKeys[i - 1];
13-
14+
1415
if (currChar != lastChar) repeatCount = 0;
15-
16+
1617
lastChar = currChar;
1718
repeatCount += 1;
18-
19+
1920
dp[i] = (dp[i] + dp[i - 1]) % MOD;
20-
21+
2122
if (i >= 2 && repeatCount >= 2) dp[i] = (dp[i] + dp[i - 2]) % MOD;
2223
if (i >= 3 && repeatCount >= 3) dp[i] = (dp[i] + dp[i - 3]) % MOD;
23-
if ((currChar == "7" || currChar == "9") && i >= 4 && repeatCount >= 4) dp[i] = (dp[i] + dp[i - 4]) % MOD;
24+
if ((currChar == "7" || currChar == "9") && i >= 4 && repeatCount >= 4) dp[i] = (dp[i] + dp[i - 4]) % MOD;
2425
}
25-
26+
2627
return dp[n];
27-
};
28+
};

0 commit comments

Comments
 (0)