Wrong test case


  • 0
    B

    I was wondered if I am wrong about that case. Can anybody tell me what is wrong with that test. Thanks for all information

    Input:
    "abba"
    "dog dog dog dog"
    Output:
    true
    Expected:
    false

    Here is my source code

    public static boolean wordPattern(String pattern, String str){
    Map<Character, String> map = new HashMap<>();
    String words[] = str.split(" ");
    for (int i = 0; i < pattern.length(); i++) {
    String s = map.get(pattern.charAt(i));
    if (pattern.length() <= words.length) {
    if (s == null) {
    map.put(pattern.charAt(i), words[i]);
    } else {
    if (!Objects.equals(s, words[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.