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

16 lines
388 B
Rust

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
}