Skip to content

Commit

Permalink
Update: 0205-isomorphic-strings.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
AkifhanIlgaz committed Jan 4, 2023
1 parent 895f110 commit 894aba8
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions rust/0205-isomorphic-strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ impl Solution {
let (mut map_s_to_t, mut map_t_to_s) = (HashMap::new(), HashMap::new());

for (c1, c2) in s.chars().zip(t.chars()) {
if (map_s_to_t.contains_key(&c1) && map_s_to_t.get(&c1) != Some(&c2))
|| (map_t_to_s.contains_key(&c2) && map_t_to_s.get(&c2) != Some(&c1))
{
return false;
if let Some(w) = map_s_to_t.insert(c1, c2) {
if w != c2 {
return false;
}
}

map_s_to_t.insert(c1, c2);
map_t_to_s.insert(c2, c1);
if let Some(w) = map_t_to_s.insert(c2, c1) {
if w != c1 {
return false;
}
}
}

true
Expand Down

0 comments on commit 894aba8

Please sign in to comment.