MCPcopy
hub / github.com/qiyuangong/leetcode / isAlienSorted

Method isAlienSorted

java/953_Verifying_an_Alien_Dictionary.java:3–13  ·  view source on GitHub ↗
(String[] words, String order)

Source from the content-addressed store, hash-verified

1class Solution {
2 HashMap<Character, Integer> orderMap = new HashMap<>();
3 public boolean isAlienSorted(String[] words, String order) {
4 // Put value index map into hashmap
5 for (int i = 0; i < order.length(); i++) {
6 orderMap.put(order.charAt(i), i);
7 }
8 for (int i = 0; i < words.length - 1; i++) {
9 if (cmp_alien(words[i], words[i + 1]) > 0) return false;
10 }
11 return true;
12
13 }
14 private int cmp_alien(String a, String b) {
15 int ls = a.length() < b.length() ? a.length(): b.length();
16 int pos = 0;

Callers

nothing calls this directly

Calls 2

cmp_alienMethod · 0.95
putMethod · 0.45

Tested by

no test coverage detected