Java error


  • 0
    H

    This solution gives me index out of bounds error even though it works fine in my IDE. Any suggestions ?

    if (s.length() != t.length()) {
    return false;
    }
    char characters[] = new char[26];//For checking visited chars
    char array1[] = s.toCharArray();
    char array2[] = t.toCharArray();

    for (int i=0; i<array1.length-1; i++) {
      char c = array1[i];
      char character = characters[c-'a'];
      if (character == '\0') {
        characters[c-'a'] = array2[i];
        continue;
      }
      if (character != array2[i]) {
        return false;
      }
    }
    return true;
    

    }


Log in to reply
 

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