Open github-actions[bot] opened 2 years ago
/*
* @lc app=leetcode id=242 lang=typescript
*
* [242] Valid Anagram
*/
// @lc code=start
function isAnagram(s: string, t: string): boolean {
if (s.length !== t.length) return false;
const so = {};
const jo = {};
for (let i = 0; i < s.length; i++) {
so[s[i]] ? (so[s[i]] += 1) : (so[s[i]] = 1);
jo[t[i]] ? (jo[t[i]] += 1) : (jo[t[i]] = 1);
};
for (const key in so) {
if (so[key] !== jo[key]) return false;
};
return true;
};
// @lc code=end
Nickname: Geeku From vscode-hzfe-algorithms
// @lc code=start
/**
* @param {number[]} nums
* @return {boolean}
*/
var containsDuplicate = function (nums) {
const map = new Map();
let result = false;
for (let i = 0; i < nums.length; i++) {
if (map.get(nums[i])) {
result = true;
break;
} else {
map.set(nums[i], true);
}
}
return result;
};
// @lc code=end
217 Contains Duplicate