Isomorphic Strings
来源:互联网 发布:全国网络诈骗报警平台 编辑:程序博客网 时间:2024/05/16 13:50
题目:
1、s中同一个字符要映射到t中的同一个字符;
2、s中通一个字符不能映射到t中的同一个字符——》t中的同一个字符要映射到s中的同一个字符
so需要s到t判断一下,t到s再判断一下;
public class Solution { public boolean isIsomorphic(String s, String t) { if (s.length() != t.length()) {return false;} return isSingleIsomorphic(s,t) && isSingleIsomorphic(t, s); }private boolean isSingleIsomorphic(String s, String t) {// TODO Auto-generated method stubHashMap<Character, Character> map = new HashMap<Character, Character>();char ch1, ch2; for (int i = 0; i < s.length(); i++) {ch1 = s.charAt(i);ch2 = t.charAt(i);if (!map.containsKey(ch1)) {map.put(ch1, ch2);}else {if (map.get(ch1) != ch2) {return false;}}} return true;}}
0 0
- Isomorphic Strings
- Isomorphic Strings
- Isomorphic Strings
- Isomorphic Strings
- Isomorphic Strings
- Isomorphic Strings
- Isomorphic Strings
- Isomorphic Strings
- Isomorphic Strings
- Isomorphic Strings
- Isomorphic Strings
- Isomorphic Strings
- Isomorphic Strings
- Isomorphic Strings
- Isomorphic Strings
- Isomorphic Strings
- Isomorphic Strings
- Isomorphic Strings
- V8 之旅:优化编译器 CRANKSHAFT
- JSONArray的运用,读取长的String字符串
- 关于openssl几个API的一点小收获
- Android学习笔记:实现图片选择器功能(下)
- css3--transform属性
- Isomorphic Strings
- 抽象类和接口的区别
- IOS多线程GCD
- ctype.h 头文件
- 产后你知道应该怎样护肤吗?
- OpenGL 法线贴图 切线空间 整理
- 凌科芯安 论:嵌入式版权保护的软硬件方案对比
- 使用SharedPreferences进行数据存储
- 矩阵乘法算法