Isomorphic Strings
You get two strings of the same length, s and t. Find out whether the letters of s can be replaced to get t: one letter always turns into the same letter, and two different letters never turn into the same one. Our example: "stone" and "ladle" — no: both s and n would have to become l.
- input
s,t: strings of the same length.- returns
trueif replacing letters ofsgivest: every occurrence of a letter by the same letter, no two letters by the same one, a letter may stay itself; otherwisefalse.- constraints
- 1 ≤ s.length ≤ 2000
- t.length == s.length
- s, t: lowercase English letters
- examples
- Open a test in the tests panel: it shows the input and the expected answer.
/**
* @param {string} s
* @param {string} t
* @return {boolean}
*/
function isIsomorphic(s, t) {
}
Ctrl ↵
format
reset
saved in this browser
Stuck?
See the solution run step by step on our example, then why it works and its complexity.
Next: more hash map problems
- 1Two SumEasysolve
- 217Contains DuplicateEasysolve
- 242Valid AnagramEasysolve
- 169Majority ElementEasysolve
- 383Ransom NoteEasysolve
- 290Word PatternEasysolve
- 219Contains Duplicate IIEasysolve
- 49Group AnagramsMediumsolve
- 128Longest Consecutive SequenceMediumsolve
- 36Valid SudokuMediumsolve
- 138Copy List with Random PointerMediumsolve
- 149Max Points on a LineHardsolve
The problem and its statement belong to LeetCode. Here are our own retelling, example and solution. Patterns Hero is not affiliated with LeetCode.