Skip to content

Commit

Permalink
Solve "205. Isomorphic Strings"
Browse files Browse the repository at this point in the history
  • Loading branch information
lancelote committed Sep 1, 2024
1 parent c7793e5 commit bbac8cf
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .plan
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Sep 1, 2024

complete top interview 150

* solve "205. Isomorphic Strings"
16 changes: 16 additions & 0 deletions src/isomorphic_strings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution:
def isIsomorphic(self, s: str, t: str) -> bool:
taken: set[str] = set()
translation: dict[str, str] = {}

for a, b in zip(s, t):
if a not in translation:
if b in taken:
return False

translation[a] = b
taken.add(b)
elif translation[a] != b:
return False

return True
16 changes: 16 additions & 0 deletions tests/test_isomorphic_strings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pytest

from src.isomorphic_strings import Solution


@pytest.mark.parametrize(
"expected,s,t",
(
(True, "egg", "add"),
(False, "foo", "bar"),
(True, "paper", "title"),
(False, "badc", "baba"),
),
)
def test_solution(expected, s, t):
assert expected is Solution().isIsomorphic(s, t)

0 comments on commit bbac8cf

Please sign in to comment.