Isomorphic Strings
来源:互联网 发布:pc手机网站源码 编辑:程序博客网 时间:2024/04/30 06:40
这道题和word pattern几乎一样,但自己还是在做出了一次大的错误后,才意识到将set改成map来做,我们能不能从中理解到奥义了!!!
public boolean isIsomorphic(String s, String t) { if (s == null) { return true; } Map<Character, Integer> setS = new HashMap<>(); Map<Character, Integer> setT = new HashMap<>(); for (int i = 0; i < s.length(); i++) { if (setS.containsKey(s.charAt(i))) { if (setT.containsKey(t.charAt(i))) { if (setS.get(s.charAt(i)).equals(setT.get(t.charAt(i)))) { continue; } else { return false; } } else { return false; } } else { if (setT.containsKey(t.charAt(i))) { return false; } else { setS.put(s.charAt(i), i); setT.put(t.charAt(i), i); } } } return true; // Set<Character> setS = new HashSet<>();// Set<Character> setT = new HashSet<>();// for (int i = 0; i < s.length(); i++) {// if (setS.contains(s.charAt(i))) {// if (setT.contains(t.charAt(i))) {// continue;// } else {// return false;// }// } else {// if (setT.contains(t.charAt(i))) {// return false;// } else {// setS.add(s.charAt(i));// setT.add(t.charAt(i));// }// }// }// 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
- SDUT 3554 无尽走廊 (动态规划) -- 解题报告
- linux修改密码
- linux设置密码规则
- 乡土中国笔记
- 求Sn=a+aa+aaa+aaaa+……+aaa…aaa(n个a)
- Isomorphic Strings
- linux的库文件为何不能单独执行
- 专技天下河北省2016年专业技术人员继续教育公需科目题库答案(答题器)
- Two Sum III - Data structure design
- 动态链接库的显示加载和隐式加载的区别
- 邮箱注册新会员,以及邮箱激活功能
- Android手机游戏浅析
- wxWidgets Tips: Compile wxWidgets 3.1.0 using Visual Studio 2015
- linux文件系统说明