id 1406159642 Time: 1 ms MemUsage: 2.3 MB

This commit is contained in:
2024-09-30 13:38:35 +09:00
parent 0efc05e3ef
commit 0773e900aa

View File

@@ -0,0 +1,28 @@
use std::collections::{HashMap, HashSet};
impl Solution {
pub fn is_isomorphic(s: String, t: String) -> bool {
let mut charmap = HashMap::new();
let mut charset = HashSet::new();
for (sc, tc) in s.chars().zip(t.chars()){
match charmap.get(&sc){
Some(&msc) => {
if msc != tc {
return false;
}
},
None => {
if charset.contains(&tc){
return false;
}
charset.insert(tc);
charmap.insert(sc, tc);
}
}
}
return true;
}
}