From b829f8467085ce3e0f58927c3486ebbccd4e25f4 Mon Sep 17 00:00:00 2001 From: Meet Bhuva Date: Thu, 26 Feb 2026 12:48:24 +0530 Subject: [PATCH] Implement isIsomorphic function in Solution class --- dart/0205-isomorphic-strings.dart | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 dart/0205-isomorphic-strings.dart diff --git a/dart/0205-isomorphic-strings.dart b/dart/0205-isomorphic-strings.dart new file mode 100644 index 000000000..fb3801fbe --- /dev/null +++ b/dart/0205-isomorphic-strings.dart @@ -0,0 +1,29 @@ +// Time Complexity: O(n) +// Space Complexity: O(1) + +class Solution { + bool isIsomorphic(String s, String t) { + if (s.length != t.length) return false; + + Map sToT = {}; + Map tToS = {}; + + for (int i = 0; i < s.length; i++) { + String currS = s[i]; + String currT = t[i]; + + if (sToT.containsKey(currS) && sToT[currS] != currT) { + return false; + } + + if (tToS.containsKey(currT) && tToS[currT] != currS) { + return false; + } + + sToT[currS] = currT; + tToS[currT] = currS; + } + + return true; + } +}