---
# System prepended metadata

title: 0953. Verifying an Alien Dictionary
tags: [Leetcode, FaceBook, Easy]

---

# 0953. Verifying an Alien Dictionary
###### tags: `Leetcode` `FaceBook` `Easy`
## 思路 O(N) O(1)
把每个字母和它的顺序map起来
## Code
```java=
class Solution {
    int[]  mapping;
    public boolean isAlienSorted(String[] words, String order) {
        mapping = new int[26];
        for(int i = 0;i < order.length();i++){
            mapping[order.charAt(i)-'a'] = i;
        }
        for(int i = 0;i < words.length-1;i++){
            if(!smaller(words[i],words[i+1])){
                return false;
            }
        }
        return true;
    }
    public boolean smaller(String a, String b){
        for(int i = 0;i<a.length() && i<b.length();i++){
            if(a.charAt(i)!=b.charAt(i)){
                return mapping[a.charAt(i)-'a']<mapping[b.charAt(i)-'a'];
            }
        }
        return a.length()<=b.length();
    }
}
```