DP in question--Decode Day is Time Limited Exceeded


  • 0
    R

    static int res=0;
    int temp=0;
    int dp(char *s,int begin,int len)
    {
    if(begin==(len-1))
    {
    if(s[begin]>='1'&&s[begin]<='9') res++;
    return 0;
    }
    if((begin+2)==len)
    {
    temp=(s[begin]-30)*10+s[begin]-30;
    if(temp>=1&&temp<=26) res++;
    return 0;
    }
    if((begin+2)<len)
    {
    dp(s,begin+2,len);
    }
    dp(s,begin+1,len);
    }

    int numDecodings(char *s) {
    int len=strlen(s);
    int begin=0;
    if(len==0) return 0;
    dp(s,begin,len);
    return res;
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.