My java 7ms use set may help u


  • 0
    B
    public boolean isIsomorphic(String s, String t) {
    			int len = s.length();
    			char[] map = new char[128];
    			HashSet<Character> set = new HashSet<Character>();
    			for (int i = 0; i < len; ++i) {
    				char sc = s.charAt(i);
    				char tc = t.charAt(i);
    				if (map[sc] == '\0') {
    					if (set.contains(tc))
    						return false;
    					map[sc] = tc;
    					set.add(tc);
    				} else if (map[sc] != tc)
    					return false;
    			}
    			return true;
    		}

Log in to reply
 

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