# LeetCode: Isomorphic Strings Solution

Use 2 hash tables

## Approach

Use two hash tables

• one for mapping char to char
• one for avoiding the case of 2 char both mapping to 1 char

## Implementation

```.css-ds3kc{display:table-row;}.css-1t8atru{display:table-cell;opacity:0.5;padding-right:var(--chakra-space-6);-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;text-align:right;}1.css-2qghsv{display:table-cell;}var isIsomorphic = function (s, t) {2  const map = new Map()3  const replaced = new Set()4  const n = s.length5
6  for (let i = 0; i < n; i++) {7    if (map.has(s[i]) === false && replaced.has(t[i]) === false) {8      map.set(s[i], t[i])9      replaced.add(t[i])10      continue11    }12
13    if (map.get(s[i]) !== t[i]) {14      return false15    }16  }17
18  return true19}```

leetcode

hash map

string

## Next Post

CSSBattle 1.8: Forking Crazy

Jul 12, 2021

Position, translate

## Previous Post

LeetCode: Find Median from Data Stream

Jul 11, 2021

Insert and keep the array sorted

Search Posts