parent
a2d7be37a2
commit
22d3ed44a1
@ -0,0 +1,34 @@
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
// 要考虑唯一双射
|
||||
public class L0205 {
|
||||
public static void main(String[] args) throws Exception {
|
||||
String s = "egg";
|
||||
String t = "app";
|
||||
System.out.print(isIsomorphic(s, t));
|
||||
}
|
||||
|
||||
public static boolean isIsomorphic(String s, String t) {
|
||||
|
||||
Map replace_chart = new HashMap();
|
||||
Map replace_chars = new HashMap();
|
||||
|
||||
int length = s.length();
|
||||
int i;
|
||||
for (i = 0; i < length; i++) {
|
||||
if (replace_chart.get(t.charAt(i)) == null) {
|
||||
replace_chart.put(t.charAt(i), s.charAt(i));
|
||||
} else if (!replace_chart.get(t.charAt(i)).equals(s.charAt(i))){
|
||||
return false;
|
||||
}
|
||||
if (replace_chars.get(s.charAt(i)) == null) {
|
||||
replace_chars.put(s.charAt(i), t.charAt(i));
|
||||
} else if (!replace_chars.get(s.charAt(i)).equals(t.charAt(i))){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue