Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions dart/0205-isomorphic-strings.dart
Original file line number Diff line number Diff line change
@@ -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<String, String> sToT = {};
Map<String, String> 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;
}
}