Skip to content

Commit a9b1e0b

Browse files
Create Duplicates checking cpp
1 parent 76b0b15 commit a9b1e0b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public:
3+
bool containsDuplicate(vector<int>& nums) {
4+
sort(nums.begin(), nums.end()); // O(n log n)
5+
for (int i = 1; i < nums.size(); ++i) {
6+
if (nums[i] == nums[i - 1]) {
7+
return true;
8+
}
9+
}
10+
return false;
11+
}
12+
};
13+

0 commit comments

Comments
 (0)