@@ -0,0 +1,2348 @@
+package main.java.com.flang.hashmap;%0A%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0A/*%0AIn an alien language, surprisingly they also use english lowercase letters, but possibly in a different order.%0AThe order of the alphabet is some permutation of lowercase letters.%0A%0AGiven a sequence of words written in the alien language, and the order of the alphabet, return true if and only%0Aif the given words are sorted lexicographicaly in this alien language.%0A%0A%0AExample 1:%0A%0AInput: words = %5B%22hello%22,%22leetcode%22%5D, order = %22hlabcdefgijkmnopqrstuvwxyz%22%0AOutput: true%0AExplanation: As 'h' comes before 'l' in this language, then the sequence is sorted.%0AExample 2:%0A%0AInput: words = %5B%22word%22,%22world%22,%22row%22%5D, order = %22worldabcefghijkmnpqstuvxyz%22%0AOutput: false%0AExplanation: As 'd' comes after 'l' in this language, then words%5B0%5D %3E words%5B1%5D, hence the sequence is unsorted.%0AExample 3:%0A%0AInput: words = %5B%22apple%22,%22app%22%5D, order = %22abcdefghijklmnopqrstuvwxyz%22%0AOutput: false%0AExplanation: The first three characters %22app%22 match, and the second string is shorter (in size.) According to lexicographical rules %22apple%22 %3E %22app%22,%0A because 'l' %3E '%E2%88%85', where '%E2%88%85' is defined as the blank character which is less than any other character (More info).%0A */%0A%0Apublic class VerifyAlienDictionary %7B%0A%0A    public boolean isAlienSorted(String%5B%5D words, String order) %7B%0A        Map%3CCharacter, Integer%3E dict = new HashMap();%0A        for (int i = 0; i %3C order.length(); i++) %7B%0A            dict.put(order.charAt(i), i);%0A        %7D%0A%0A        int len = words.length;%0A        for (int i = 0; i %3C len - 1; i++) %7B%0A            int rst = 0;%0A            String s1 = words%5Bi%5D;%0A            String s2 = words%5Bi+1%5D;%0A            int j = s1.length();%0A            int k = s2.length();%0A            // get the shorter word%0A            int min = Math.min(j, k);%0A            for (int z = 0; z %3C min && rst == 0; z++) %7B%0A                // if the subtraction of two characters location is -1, the order is correct, continue%0A                rst = dict.get(s1.charAt(z)) - dict.get(s2.charAt(z));%0A            %7D%0A            // if the subtraction larger than 0 or equals to 0 and second string length is smaller than first%0A            // one (example 3), it means the words are not in order%0A            if (rst %3E 0 %7C%7C (rst == 0 && min == k)) %7B%0A                return false;%0A            %7D%0A        %7D%0A%0A        return true;%0A    %7D%0A%7D%0A

Create VerifyAlienDictionary.java