/** 205. Isomorphic Strings * 2016-6-8 by Mingyang * With the same pattern as we did last time, with the HashMap do just fine * This topic can not be underestimated, the first time easy to do wrong, a B,BB Case But * because we do not know B when saving a, so we not only have to determine whether the key is not, but also to determine whether the value has * only if the key and value are equal to the best results*/ Public Static Booleanisisomorphic (string s, String t) {intlens=s.length (); intLent=t.length (); if(lent!=lens)return false; HashMap<Character,Character> map=NewHashmap<character,character>(); for(inti=0;i<lens;i++){ Chartemp=S.charat (i); Charnun=T.charat (i); if(!map.containskey (temp) &&!Map.containsvalue (nun)) {map.put (Temp,nun); }Else{ if(Map.containskey (temp) &&nun== (Map.get (temp)))//here is a new addition to the judgment condition, that is, when the map does not contain temp, cannot judge this condition. Because it's possible to get here just because the map contains nun. Continue; Else return false; } } return true;}
205. Isomorphic Strings