why is wrong answer?


  • 0
    H

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

    int lens=strlen(s);
    if(lens<=1) return true;
    int counts=1,countt=1;
    bool shibushi=true;
    for(int i=1;i<lens;i++)
    {
    
      if(s[i]==s[i-1])
      {counts++;}
      if(s[i]!=s[i-1]){counts=1;}
      
      if(t[i]==t[i-1])
      {countt++;}
      if(t[i]!=t[i-1]){countt=1;}
      
       if (counts!=countt) {shibushi=false;break;}
    
        
    }
    
    return shibushi;
    

    }


  • 0
    P

    It's wrong because your code only checked weather the length of repeat substring is equal rather than weather the map is injection, i.e. if a letter in s is mapped to a letter in t, then any other letter in s can not be mapped to the same letter in t.
    For example:
    "ab"->"bc“: 'a'->'b', 'b'->'c', that's good.
    "ab"->"aa": 'a'->'a', 'b'->'a', bad.


Log in to reply
 

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