Java HashMap Storage Issues

Source: Internet
Author: User

1  Public Static Booleanisisomorphic (string s, String t) {2Map Map1 =NewHashmap<>();3Map MAP2 =NewHashmap<>();4      for(inti = 0; I < s.length (); i++) {5         if(Map1.put (S.charat (i), i)! =Map2.put (T.charat (i), i))6         {7             return false;8         }9     }Ten     return true; One}

Leetcode Connection https://leetcode.com/problems/isomorphic-strings/

The above code line 4th, I is the type of "int", at this time on the Leetcode submitted to make a judgment program will be wrong. Instead of changing the type of I to "Integer" the program does not error.

One explanation: When map stores the value, it converts the I value to the "Integer" type, and when stored, the same value generates two objects, so an error is judged when the comparison is equal.

The explanation seems to be correct. However, I am on the Windows Idea +jdk1.8 test a lot of mistakes are not errors, is it the leetcode of the online test environment caused? Unknown, awaiting confirmation ....

Java HashMap Storage Issues

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.