Skip to content

Commit f3560cb

Browse files
authored
Merge pull request neetcode-gh#1868 from AkifhanIlgaz/0205
Create: 0205-isomorphic-strings.rs
2 parents d6553e9 + 895f110 commit f3560cb

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

rust/0205-isomorphic-strings.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use std::collections::HashMap;
2+
3+
impl Solution {
4+
pub fn is_isomorphic(s: String, t: String) -> bool {
5+
let (mut map_s_to_t, mut map_t_to_s) = (HashMap::new(), HashMap::new());
6+
7+
for (c1, c2) in s.chars().zip(t.chars()) {
8+
if (map_s_to_t.contains_key(&c1) && map_s_to_t.get(&c1) != Some(&c2))
9+
|| (map_t_to_s.contains_key(&c2) && map_t_to_s.get(&c2) != Some(&c1))
10+
{
11+
return false;
12+
}
13+
14+
map_s_to_t.insert(c1, c2);
15+
map_t_to_s.insert(c2, c1);
16+
}
17+
18+
true
19+
}
20+
}

0 commit comments

Comments
 (0)