Giving wrong answer


  • 0
    B

    Why this code is giving wrong answer ?? The testcse No #22 got failed and it says the characters could be space . why? We cannot take characters as in question it is written that we have to take only small letters.

    bool isAnagram(char* s, char* t) {

    int i,j,flag=0;
    int count[26];
    int count1[26];
    
    for(i=0;s[i]!='\0';i++)
    {
        count[s[i]-'a']++;
    }
    
    for(i=0;t[i]!='\0';i++)
    {
        count1[t[i]-'a']++;
    }
    
    for(i=0;i<26;i++)
    {
        if(count[i]!=count1[i])
        {
            flag=1;
            break;
        }
    }
    if(flag==1)
    {
        return false;
    }
    else
    return true;
    

    }


Log in to reply
 

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