Why i failed in submission but succeed in run code on this test case?


  • 0
    X

    i have pass 60% test case but i failed in the test case of s1="a" s2 ="b" s3="ab"

    can anybody help me ?

    bool isInterleave(char* s1, char* s2, char* s3) {
                int dp[100][100];
                memset(dp,0,sizeof(dp));
                int stack[100][3];
                memset(stack,0,sizeof(stack));
                int ss = 0;
                int i=0,j=0,index=0;
                dp[0][0]=0;
                while(s3[index]!='\0')
                {
                    if(s3[index] == s1[i]||s3[index]== s2[j])
                    {
                        if (s3[index] == s1[i]&&s3[index]==s2[j]&&(dp[j+1][i]!=1||dp[j][i+1]!=1)) {
                            stack[ss][0]=index;
                            stack[ss][1]=i;
                            stack[ss][2]=j;
                            ss++;
                        }
                        if(s3[index] ==s1[i]&&dp[j][i+1]==0)
                        {
                            index++;
                            i++;
                            dp[j][i]=1;
                            continue;
                        }
                        else if(s3[index]==s2[j]&&dp[j+1][i]==0)
                        {
                            index++;
                            j++;
                            dp[j][i]=1;
                            continue;
                        }
                    }
                    if (ss<1) {
                        return false;
                    }
                    {
                        index = stack[ss-1][0];
                        i=stack[ss-1][1];
                        j=stack[ss-1][2];
                        ss--;
                        continue;
                    }
                }
                return true;
            }

  • 0
    L

    I have encountered the same problem when I run test as s1 = "a", s2 = "", s3 = "c". The local run code answer is false, but the submission answer is true. I feel puzzle about it.


  • 0
    X

    yeah i also confronted same situation in some other problem~~~~~


Log in to reply
 

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