All files / leetCode 0205.ts

100% Statements 13/13
100% Branches 6/6
100% Functions 1/1
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19  9x 1x 8x 2x   6x 6x   6x 21x 4x 17x 17x     2x    
export default function isIsomorphic(s: string, t: string): boolean {
  if (s.length !== t.length)
    return false
  if (s.length < 2)
    return true
 
  const encodeS = new Map<string, number>()
  const encodeT = new Map<string, number>()
 
  for (let i = 0; i < s.length; i++) {
    if (encodeS.get(s[i]) !== encodeT.get(t[i]))
      return false
    encodeS.set(s[i], i)
    encodeT.set(t[i], i)
  }
 
  return true
}