leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
2370.cpp (376B)
0 class Solution {
1 public:
2 int longestIdealString(const string &s, int k) const {
3 static int dp[256];
4 int res = 0;
6 memset(dp, 0x00, sizeof(dp));
7 for (const char c : s) {
8 for (int j = c - k; j <= c + k; j++)
9 dp[c] = max(dp[c], dp[j]);
10 res = max(res, ++dp[c]);
11 }
13 return res;
14 }
15 };