Open Zheaoli opened 2 years ago
/*
* @lc app=leetcode id=217 lang=typescript
*
* [217] Contains Duplicate
*/
// @lc code=start
function containsDuplicate(nums: number[]): boolean {
const obj = {};
for (let i = 0; i < nums.length; i++) {
if (!obj[nums[i]]) {
obj[nums[i]] = true;
continue;
} else {
return true;
}
}
return false;
};
// @lc code=end
微信id: 弘树 来自 vscode 插件
/*
* @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
微信id: 弘树 来自 vscode 插件
2022-08-23