精髓就在于用map来存储新规定序列的顺序
class Solution {
public boolean isAlienSorted(String[] words, String order) {
HashMap<Character,Integer> map = new HashMap<>();
for(int i=0;i<order.length();i++){
map.put(order.charAt(i),i);
}
for(int i=0;i<words.length-1;i++){
if(!compare(words[i],words[i+1],map)) return false;
}
return true;
}
public boolean compare(String a,String b,HashMap<Character,Integer> map){
int i=0;
for(;i<a.length()&&i<b.length();i++){
if(map.get(a.charAt(i))<map.get(b.charAt(i))){
return true;
}else if(map.get(a.charAt(i))>map.get(b.charAt(i))){
return false;
}
}
if(i<a.length()) return false;
return true;
}
}