1
Fork 0
leetcode/source/isomorphic_strings/mod.rs

16 lines
388 B
Rust
Raw Permalink Normal View History

2022-04-09 18:25:08 +00:00
pub fn is_isomorphic(a: String, b: String) -> bool {
let mut map_a = std::collections::HashMap::new();
let mut map_b = std::collections::HashMap::new();
for (a, b) in a.chars().zip(b.chars()) {
let from_map_a = *map_a.entry(a).or_insert(b);
let from_map_b = *map_b.entry(b).or_insert(a);
if from_map_b != a || from_map_a != b {
return false;
}
}
true
}