Alien Dictionary (Mutation)
Alien Dictionary (Leetcode 269 mutation) (Correctness Unchecked)
Simplify version of Leetcode 269
Question
Given String[] words and char[] ordering,decide whether the words match with the ordering,return true or false. E.g. words = {"apple", "append", "boy", "zoo", "zpcore"}, ordering = {'a','b','z','g','o','p'}, return true; words = {"apple", "append", "boy", "zoo", "zpcore"}, ordering = {'b','a','b','z','g','o','p'}, return false;
Solution
KeyNote: 1. Only compare the two first characters from the two string where the mismatch starts. 2. We can use hashmap to judge the two characters' sequence in O(1) time complexity. Map(character->position in ordering)
Last updated