Can anyone tell me what's wrong with my code?

  • 0

    Hi,guys, I am trying to use hashmap but it doesn't work. When I change hashmap to int[], it is accepted. I have tried to figure out the reason for a long time, but just failed. Hope somebody can help me with it. Here is my code using hashmap:
    ''' public boolean isIsomorphic(String s, String t) {
    if(s==null||t==null||s.length()!=t.length())return false;
    HashMap<Character,Integer> sMap=new HashMap<>();
    HashMap<Character,Integer> tMap=new HashMap<>();
    int len=s.length();
    for(int i=0;i<len;i++){
    if(sMap.get(s.charAt(i))!=tMap.get(t.charAt(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.