Time limit exceeded


  • 0
    G

    class Solution {
    public:
    bool isInterleave(string s1, string s2, string s3) {
    return isInterleaveUtil(s1, s2, s3, s1.length(), s2.length(), s3.length() );
    }

    bool isInterleaveUtil( string s1, string s2, string s3, int a, int b, int c)
    {
        if( a==-1 && b==-1 && c==-1)
            return true;
        if( c==-1)
            return false;
        return (s1[a-1] == s3[c-1] && isInterleaveUtil(s1, s2, s3, a-1, b, c-1)) || (s2[b-1] == s3[c-1] && isInterleaveUtil(s1, s2, s3, a, b-1, c-1));
    }
    

    };


Log in to reply
 

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