var twoSum = function (nums, target) {
const map = {};
for (let i = 0; i < nums.length; i++) {
const diff = target - nums[i];
if (map.hasOwnProperty(diff)) {
return [map[diff], i];
} else {
map[nums[i]] = i;
}
}
return [];
};
var isAnagram = function (s, t) {
if (s.length !== t.length) {
return false;
}
let map = new Array(26).fill(0);
for (let i = 0; i < s.length; i++) {
map[s.charCodeAt(i) - 97]++;
}
for (let j = 0; j < t.length; j++) {
const currCode = t.charCodeAt(j) - 97;
map[currCode]--;
if (map[currCode] < 0) {
return false;
}
}
return true;
};