Why can't this solution pass the last test case

  • 4

    I can't see logic problems in the following code, but it cannot pass the last super long test case. Anybody know the reason?

    import java.util.HashMap;
    import java.util.Map;
    public class Solution {
        public boolean isIsomorphic(String s, String t) {
            if(s.length() != t.length()) return false;
            Map<Character,Integer> map1 = new HashMap<Character,Integer>();
            Map<Character,Integer> map2 = new HashMap<Character,Integer>();
            for(int i = 0; i < s.length(); i++){
            	if(map1.put(s.charAt(i), i) != map2.put(t.charAt(i), i)) return false;
            return true;

  • 0

    Confused too. MARK

  • 0

    similar code same confusion. mark

  • 0

    Same here. Mark...

  • 0

    Confused too. The fact we know is that two Integer objects are created from "int" (or taken from that cache), and they might not be the same. Operation == compares object.

Log in to reply

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