diff --git a/contains-duplicate/sol.js b/contains-duplicate/sol.js new file mode 100644 index 0000000..ea8def5 --- /dev/null +++ b/contains-duplicate/sol.js @@ -0,0 +1,14 @@ +/** + * @param {number[]} nums + * @return {boolean} + */ +var containsDuplicate = function(nums) { + let exists = {}; + return nums.some(n => { + if (exists[n]) { + return true; + } + exists[n] = true; + return false; + }); +}; \ No newline at end of file diff --git a/contains-duplicate/sol.py b/contains-duplicate/sol.py new file mode 100644 index 0000000..9d22659 --- /dev/null +++ b/contains-duplicate/sol.py @@ -0,0 +1,8 @@ +class Solution: + def containsDuplicate(self, nums: List[int]) -> bool: + exists = {} + for n in nums: + if n in exists: + return True + exists[n] = True + return False \ No newline at end of file diff --git a/contains-duplicate/sol.ts b/contains-duplicate/sol.ts new file mode 100644 index 0000000..239d1e9 --- /dev/null +++ b/contains-duplicate/sol.ts @@ -0,0 +1,10 @@ +function containsDuplicate(nums: number[]): boolean { + let exists = {}; + return nums.some(n => { + if (exists[n]) { + return true; + } + exists[n] = true; + return false; + }); +}; \ No newline at end of file