Less than 20line, 4ms.(c++)


  • 0
    H

    '''
    class Solution {
    public:
    unordered_map<int, bool> cache;
    bool poop(string& s1, string& s2, string& s3, int p1, int p2){
    if(s3[p1 + p2] == '\0') return true;
    if(cache[p1s3.length() + p2] == 1) return false;
    cache[p1
    s3.length() + p2] = 1;
    if(s1[p1] == s3[p1+p2])
    if(poop(s1, s2, s3, p1+1, p2)) return true;
    if(s2[p2] == s3[p1+p2])
    if(poop(s1, s2, s3, p1, p2+1)) return true;
    return false;
    }
    bool isInterleave(string s1, string s2, string s3) {
    if(s1.length() + s2.length() != s3.length()) return false;
    return poop(s1, s2, s3, 0, 0);
    }
    };
    '''


Log in to reply
 

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