Open
Description
index.ts
export function areAnagrams(s: string, t: string): boolean {
if (s.length !== t.length) {
return false;
}
const sFreq: Map<string, number> = new Map();
const tFreq: Map<string, number> = new Map();
for (let i = 0; i < s.length; i++) {
sFreq.set(s[i], (sFreq.get(s[i]) || 0) + 1);
tFreq.set(t[i], (tFreq.get(t[i]) || 0) + 1);
}
for (const [char, count] of sFreq) {
if (tFreq.get(char) !== count) {
return false;
}
}
return true;
}