class Solution {
public boolean isAlienSorted(String[] words, String order) {
int n = words.length;
int len = order.length();
Map<Character,Integer> map = new HashMap<>();
for(int i = 0;i < len;i++){
map.put(order.charAt(i),i);
}
for(int i = 0;i < n - 1;i++){
int max = Math.max(words[i].length(),words[i + 1].length());
for(int j = 0;j < max;j++){
if(j >= words[i].length() && j < words[i + 1].length()){
break;
}
if(j < words[i].length() && j >= words[i + 1].length()){
return false;
}
if(map.get(words[i].charAt(j)) < map.get(words[i + 1].charAt(j))){
break;
}
if(map.get(words[i].charAt(j)) > map.get(words[i + 1].charAt(j))){
return false;
}
}
}
return true;
}
}
03-31
3857
03-28