From 839664de9dd2178ddf3f31b16b1d2cf1fd0da1f1 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 17 Nov 2024 04:07:28 -0600 Subject: [PATCH] adding isomorphic strings algo --- .../isomorphic_strings.py | 7 +++++++ .../test_isomorphic_strings_round_11.py | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/my_project/interviews/top_150_questions_round_11/isomorphic_strings.py create mode 100644 tests/test_150_questions_round_11/test_isomorphic_strings_round_11.py diff --git a/src/my_project/interviews/top_150_questions_round_11/isomorphic_strings.py b/src/my_project/interviews/top_150_questions_round_11/isomorphic_strings.py new file mode 100644 index 00000000..b4c616af --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_11/isomorphic_strings.py @@ -0,0 +1,7 @@ +from typing import List, Union, Collection, Mapping, Optional +from abc import ABC, abstractmethod + +class Solution: + def isIsomorphic(self, s: str, t: str) -> bool: + + return len(set(zip(s,t))) == len(set(s)) == len(set(t)) \ No newline at end of file diff --git a/tests/test_150_questions_round_11/test_isomorphic_strings_round_11.py b/tests/test_150_questions_round_11/test_isomorphic_strings_round_11.py new file mode 100644 index 00000000..688f4991 --- /dev/null +++ b/tests/test_150_questions_round_11/test_isomorphic_strings_round_11.py @@ -0,0 +1,17 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_11\ +.isomorphic_strings import Solution + +class IsomorphicStringsTestCase(unittest.TestCase): + + def test_are_isomorphic_strings(self): + solution = Solution() + output = solution.isIsomorphic(s="egg", t="add") + self.assertTrue(output) + + def test_are_not_isomorphic_strings(self): + solution = Solution() + output = solution.isIsomorphic(s="foo", t="bar") + self.assertFalse(output) + + \ No newline at end of file