Skip to content

Commit 150a435

Browse files
committed
contains-duplicate solution
1 parent c10802e commit 150a435

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

contains-duplicate/nayeongdev.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {boolean}
4+
* O(nlog(n)) : 정렬 O(nlog(n)) + 탐색 O(n)
5+
*/
6+
var containsDuplicate = function (nums) {
7+
const sortedNums = nums.toSorted((a, b) => a - b)
8+
for (let i = 0; i < nums.length - 1; i++) {
9+
if (sortedNums[i] === sortedNums[i + 1]) {
10+
return true
11+
}
12+
}
13+
return false
14+
};

0 commit comments

Comments
 (0)