contains duplicate in 3 more languages for some reason

This commit is contained in:
Gleb Koval 2022-05-29 21:00:01 +01:00
parent 2a7ec7e34b
commit e7b17e4450
3 changed files with 32 additions and 0 deletions

14
contains-duplicate/sol.js Normal file
View File

@ -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;
});
};

View File

@ -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

10
contains-duplicate/sol.ts Normal file
View File

@ -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;
});
};