From e7b17e44504a0058cf409cca6fdb6727773ac07d Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Sun, 29 May 2022 21:00:01 +0100 Subject: [PATCH] contains duplicate in 3 more languages for some reason --- contains-duplicate/sol.js | 14 ++++++++++++++ contains-duplicate/sol.py | 8 ++++++++ contains-duplicate/sol.ts | 10 ++++++++++ 3 files changed, 32 insertions(+) create mode 100644 contains-duplicate/sol.js create mode 100644 contains-duplicate/sol.py create mode 100644 contains-duplicate/sol.ts 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