# LeetCode: Verifying An Alien Dictionary Solution

`.css-ds3kc{display:table-row;}.css-1t8atru{display:table-cell;opacity:0.5;padding-right:var(--chakra-space-6);-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;text-align:right;}1.css-2qghsv{display:table-cell;}/**2 * @param {string[]} words3 * @param {string} order4 * @return {boolean}5 */6var isAlienSorted = function (words, order) {7  const N = words.length8  order = order.split("").reduce((acc, char, i) => acc.set(char, i), new Map())9  let sorted = true10  for (let i = 0; i < N - 1; i++) {11    for (let j = 0; j < words[i].length; j++) {12      if (order.get(words[i][j]) === order.get(words[i + 1][j])) {13        continue14      } else if (order.get(words[i][j]) < order.get(words[i + 1][j])) {15        break16      } else {17        sorted = false18      }19    }20  }21  return sorted22}`

leetcode

hash table

## Next Post

LeetCode: Longest Increasing Path In A Matrix

Apr 10, 2021

Search Posts