Skip to content

Instantly share code, notes, and snippets.

@nickangtc
Created May 20, 2023 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickangtc/63b70b5c175202bf85af6bd4e312428f to your computer and use it in GitHub Desktop.
Save nickangtc/63b70b5c175202bf85af6bd4e312428f to your computer and use it in GitHub Desktop.
LeetCode Contains Duplicates (solution)
// https://leetcode.com/problems/contains-duplicate/
// this solution beats 85% of other submissions in terms of runtime, 57% in terms of memory
/**
* @param {number[]} nums
* @return {boolean}
*/
var containsDuplicate = function(nums) {
const memo = {};
for (let i = 0; i < nums.length; i++) {
const num = nums[i];
const seenBefore = memo[num];
if (seenBefore) {
return true;
}
memo[num] = true;
}
return false;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment