205. Isomorphic Strings

Source: Internet
Author: User

        /** 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.