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