Missing test case


  • 0

    So this is my code and it was accepted.

    public class Solution {
        public boolean wordPattern(String pattern, String str) {
            String[] array = str.split(" ");
            if(array.length != pattern.length()) return false;
            Set<Character> setP = new HashSet<>();
            Set <String> setS = new HashSet<>();
            for(int i = 0; i< pattern.length(); i++) {
                if(setP.add(pattern.charAt(i)) != setS.add(array[i])) return false;
            }
            return true;
        }
    }
    

    However, this code should not be accepted because it would fail when the inputs are:
    "aba"
    "cat cat cat dog"


Log in to reply
 

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