Isomorphic Strings

来源:互联网 发布:博拉网络上市最新消息 编辑:程序博客网 时间:2024/04/30 17:29


public class Solution {    public boolean isIsomorphic(String s, String t) {        if (s == null || t == null) {            return false;        }        char[] ss = s.toCharArray();        char[] tt = t.toCharArray();        int length = ss.length;        HashMap<Character, Integer> map1 = new HashMap<Character, Integer>();        HashMap<Character, Integer> map2 = new HashMap<Character, Integer>();        for (int i = 0; i < length; i++) {            if (map1.containsKey(ss[i])) {                int loc = map1.get(ss[i]);                if (tt[i] != tt[loc]) {                    return false;                }            } else {                if (map2.containsKey(tt[i])) {                    return false;                }            }            map1.put(ss[i], i);            map2.put(tt[i], i);                    }        return true;    }}


0 0
原创粉丝点击