242. Valid Anagram

202410121055
tags: #hash-map

var isAnagram = function(s, t) {
	const map = new Map();
	for (const c of s) {
		map.set(c, (map.get(c) ?? 0) + 1);
	}
	for (const c of t) {
		map.set(c, (map.get(c) ?? 0) - 1);
	}
	for (const val of map.values()) {
		if (val !== 0) {
			return false;
		}
	}
	return true;
};

Reference

https://leetcode.com/problems/valid-anagram/