Skip to main content
Back to problems
Leetcode
Medium
Hash Maps
Strings
Isomorphic Strings

Determine whether two strings can be transformed into each other with a one-to-one character mapping.

Acceptance 0%
Problem Statement

Given two strings s and t, determine whether they are isomorphic.

Two strings are isomorphic if the characters in s can be replaced to get t with a consistent mapping.

  • Each character in s must map to exactly one character in t.
  • No two different characters in s may map to the same character in t.
  • The mapping must preserve the order of characters.

Return true if the strings are isomorphic, otherwise return false.

Input Format

Two strings s and t.

Output Format

Return a boolean indicating whether the strings are isomorphic.

Constraints

Assume both strings consist of ASCII characters unless otherwise specified by the platform. The strings are typically of equal length for a valid isomorphism check.

Examples
Sample cases returned by the problem API.

Example 1

Input

s = "egg", t = "add"

Output

true

Explanation

The mapping can be e -> a and g -> d.

Example 2

Input

s = "foo", t = "bar"

Output

false

Explanation

The character o would need to map to both a and r, which is not allowed.

Show 1 more example

Example 3

Input

s = "paper", t = "title"

Output

true

Explanation

A consistent one-to-one mapping exists: p -> t, a -> i, e -> l, r -> e.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.