class Solution {
public boolean isAlienSorted(String[] words, String order) {
int[] index = new int[26];
for(int i = 0; i < order.length(); ++i){ // 字母正确顺序表
index[order.charAt(i) - 'a'] = i;
}
boolean valid = false;
// 遍历words比较字典序
for (int i = 0; i < words.length-1; i++) {
for (int j = 0; j<words[i].length()&&j<words[i+1].length(); j++) {
int index1 = index[words[i].charAt(j) - 'a'];
int index2 = index[words[i+1].charAt(j) - 'a'];
if(index1>index2){
return false;
}else if(index1<index2){
valid = true;
break;
}
}
if (!valid){
if(words[i].length()>words[i+1].length()){
return false;
}
}
}
return true;
}
}