Leetcode 467. Surround the only substring in the string (DAY 46) ---- Dynamic programming learning period

Original title

Insert picture description here



Code implementation (most of the first brush to see the solution, a small part of self-solving)

int findSubstringInWraproundString(char * p){
    
    
    int i,charlength = strlen(p),dp[26] = {
    
    0},pre = -2,temp,sum = 0,cur;
    for(i=0;i<charlength;i++)
    {
    
    
        temp = p[i] - 97;
        if(temp == 1 + pre || temp == pre - 25)
            cur++;
        else
            cur = 1;
        dp[temp] = fmax(cur,dp[temp]);
        pre = temp;
    }
    for(i=0;i<26;i++)
        sum += dp[i];
    return sum;
}

Guess you like

Origin blog.csdn.net/qq_37500516/article/details/113824204