当前位置:   article > 正文

Java | Leetcode Java题解之第205题同构字符串

Java | Leetcode Java题解之第205题同构字符串

题目:

题解:

  1. class Solution {
  2. public boolean isIsomorphic(String s, String t) {
  3. Map<Character, Character> s2t = new HashMap<Character, Character>();
  4. Map<Character, Character> t2s = new HashMap<Character, Character>();
  5. int len = s.length();
  6. for (int i = 0; i < len; ++i) {
  7. char x = s.charAt(i), y = t.charAt(i);
  8. if ((s2t.containsKey(x) && s2t.get(x) != y) || (t2s.containsKey(y) && t2s.get(y) != x)) {
  9. return false;
  10. }
  11. s2t.put(x, y);
  12. t2s.put(y, x);
  13. }
  14. return true;
  15. }
  16. }
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号