Skip to content

Commit 9788a73

Browse files
committed
contains duplicate solution
1 parent c10802e commit 9788a73

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <bits/stdc++.h>
2+
3+
class Solution {
4+
public:
5+
bool containsDuplicate(vector<int>& nums) {
6+
sort(nums.begin(), nums.end());
7+
8+
for(int i = 0; i < nums.size() - 1; i++)
9+
if(nums[i] == nums[i+1])
10+
return true;
11+
12+
return false;
13+
}
14+
};
15+
16+
// ์ฒซ ์‹œ๋„ ๋ฐ ํ‹€๋ฆฐ ํ’€์ด
17+
// ํ‹€๋ฆฐ ์ด์œ :
18+
// leetcode๋Š” ์ฒ˜์Œ ํ’€์–ด๋ณด๋Š”๋ฐ, ๋ฐฑ์ค€๋ณด๋‹ค ์‹œ๊ฐ„ ์ œํ•œ์ด ์—„๊ฒฉํ•จ
19+
// -> 20์–ต ๋ฐฐ์—ด ์„ ์–ธํ•˜๋Š”๊ฒƒ๋งŒ์œผ๋กœ๋„ ์‹œ๊ฐ„์ดˆ๊ณผ ๋ฐœ์ƒ
20+
//
21+
// class Solution {
22+
// public:
23+
// bool containsDuplicate(vector<int>& nums) {
24+
// vector<bool> check(2'000'000'001, false);
25+
// int offset = 1'000'000'000;
26+
27+
// for(int i = 0; i < nums.size(); i++) {
28+
// int idx = nums[i] + offset;
29+
30+
// if(check[idx] == true)
31+
// return true;
32+
// check[idx] = true;
33+
// }
34+
// return false;
35+
// }
36+
// };

0 commit comments

Comments
ย (0)