JAVA 2MS solution hasmap

  • 3
    public boolean wordPattern(String pattern, String str) {
        String[] strs = str.split(" ");
        int length = pattern.length();
        if(strs.length!=length)return false;
        Map<String,Integer> map = new HashMap<String,Integer>();
        for(Integer i = 0;i<length;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.