Skip to content

Commit eae9bb0

Browse files
committed
contains-duplicate
1 parent 6e112ea commit eae9bb0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

contains-duplicate/taewanseoul.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* 217. Contains Duplicate
3+
* Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.
4+
* https://leetcode.com/problems/contains-duplicate/description/
5+
*/
6+
function containsDuplicate(nums: number[]): boolean {
7+
const isDuped = new Set(nums).size !== nums.length;
8+
9+
return isDuped ? true : false;
10+
}
11+
12+
// TC: O(n)
13+
// https://262.ecma-international.org/15.0/index.html#sec-get-set.prototype.size
14+
// Set objects must be implemented using either hash tables or other mechanisms that, on average, provide access times that are sublinear on the number of elements in the collection. The data structure used in this specification is only intended to describe the required observable semantics of Set objects. It is not intended to be a viable implementation model.

0 commit comments

Comments
 (0)