2266. 统计打字方案数
题目链接:2266. 统计打字方案数
代码如下:
class Solution {
public:
int countTexts(string pressedKeys) {
vector<long long> f(pressedKeys.size() + 1);
f[0] = f[1] = 1;
for (int i = 1; i < pressedKeys.size(); i++) {
f[i + 1] = f[i];
if (pressedKeys[i] == pressedKeys[i - 1]) {
f[i + 1] += f[i - 1];
if (i >= 2 && pressedKeys[i] == pressedKeys[i - 2]) {
f[i + 1] += f[i - 2];
}
if (i >= 3 && (pressedKeys[i] == '7' || pressedKeys[i] == '9') && pressedKeys[i] == pressedKeys[i - 2] && pressedKeys[i] == pressedKeys[i - 3]) {
f[i + 1] += f[i - 3];
}
f[i + 1] %= 1'000'000'007;
}
}
return f[pressedKeys.size()];
}
};
标签:方案,int,打字,pressedKeys,&&,2266,size
From: https://blog.csdn.net/weixin_45256307/article/details/145236674