My AC java solution (nearly the same with question "Isomorphic Strings")

  • 0

    I found this question is nearly the same with "Isomorphic Strings", here is my ac solution:

    public boolean wordPattern(String pattern, String str) {
            Map<Character, Integer> map1 = new HashMap<Character, Integer>();
            Map<String, Integer> map2 = new HashMap<String, Integer>();
            String[] strArray = str.split(" ");
            if (pattern.length() != strArray.length) return false;
            for (Integer i = 0; i < pattern.length(); i++) {
                if (map1.put(pattern.charAt(i), i) != map2.put(strArray[i], i)) return false;
            return true;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.