leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

2370.cpp (376B)


      1 class Solution {
      2   public:
      3     int longestIdealString(const string &s, int k) const {
      4         static int dp[256];
      5         int res = 0;
      6 
      7         memset(dp, 0x00, sizeof(dp));
      8         for (const char c : s) {
      9             for (int j = c - k; j <= c + k; j++)
     10                 dp[c] = max(dp[c], dp[j]);
     11             res = max(res, ++dp[c]);
     12         }
     13 
     14         return res;
     15     }
     16 };