deno.land / x / masx200_leetcode_test@10.6.5 / unique-morse-code-words / index.ts
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849export default function uniqueMorseRepresentations(words: string[]): number { const translations = words.map((word) => Array.from(word) .map((v) => { const m = letterToMorse.get(v);
if (typeof m === "undefined") { throw Error("invalid word"); } return m; }) .join("") );
const seen = new Set<string>(translations); return seen.size;}const MORSE = [ ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..",];const letterToMorse = new Map( MORSE.map((v, i) => [String.fromCharCode(i + "a".charCodeAt(0)), v]),);
Version Info