Created
May 20, 2023 12:47
-
-
Save nickangtc/63b70b5c175202bf85af6bd4e312428f to your computer and use it in GitHub Desktop.
LeetCode Contains Duplicates (solution)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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