---
# System prepended metadata

title: \#290 Word Pattern
tags: [leetcode, leetcode-easy]

---

# \#290 Word Pattern
## *給定字串pattern和s, 確認s是否為pattern的"模型樣式"*
## *ex. pattern:aabb <==> s:dog dog cat cat*
## Log
 - build 20210609 by syhuang

## xxx
 - xxx
```javascript=
```
## 初見
 - 與先前某題類似, 用map下去做每個word和letter的對照, 反過來再做一次以免出現不同word(letter)對應到相同letter(word)的情況
```javascript=
var wordPattern = function(pattern, s) {
    var pary = pattern.split('');
    var sary = s.split(' ');    
    return bijection(pary,sary) && bijection(sary,pary);
    
    function bijection(ary_1,ary_2){
        if(ary_1.length != ary_2.length) return false;
        var map = new Map();
        for(var i=0; i<ary_1.length; i++){
            if(map.has(ary_1[i])){
                if(map.get(ary_1[i]) !== ary_2[i]) return false;
            }else{
                map.set(ary_1[i],ary_2[i]);
            }
        }
        return true;
    }
};
```
## 備註
 - 另有使用第三目標變數用來被對應, 當word/letter對應到不同變數時即為不映射
## 參考
###### tags: `leetcode`, `leetcode-easy`