|
307 | 307 | // If the letter does not exist, create a map and map it to the value |
308 | 308 | // of the second letter |
309 | 309 | if (letterMap[letterA] === undefined) { |
310 | | - letterMap[letterA] = letterB; |
| 310 | + // If letterB has already been added to letterMap, then we can say: they are not isomorphic. |
| 311 | + if(secondString.indexOf(letterB) < i){ |
| 312 | + return false; |
| 313 | + } else { |
| 314 | + letterMap[letterA] = letterB; |
| 315 | + } |
311 | 316 | } else if (letterMap[letterA] !== letterB) { |
312 | 317 | // Eles if letterA already exists in the map, but it does not map to |
313 | 318 | // letterB, that means that A is mapping to more than one letter. |
|
0 commit comments