---
# System prepended metadata

title: 0290. Word Pattern
tags: [Leetcode, Easy]

---

# 0290. Word Pattern
###### tags: `Leetcode` `Easy`
Link: https://leetcode.com/problems/word-pattern/
## 思路
### 思路一
### 思路二
## Code
### 思路一
```java=
class Solution {
    public boolean wordPattern(String pattern, String s) {
        Map<Character, String> mapChar = new HashMap<>();
        Map<String, Character> mapWord = new HashMap<>();
        String[] words = s.split(" ");
        
        if(words.length!=pattern.length()) return false;
        for(int i = 0;i < words.length;i++){
            char c = pattern.charAt(i);
            if(!mapChar.containsKey(c)){
                if(mapWord.containsKey(words[i])){
                    return false;
                }
                else{
                    mapChar.put(c, words[i]);
                    mapWord.put(words[i], c);
                }
            }
            else{
                if(!mapChar.get(c).equals(words[i])) return false;
            }
        }
        return true;
    }
}
```
### 思路二
```java=

```