Skip to content

Commit 4ec24ba

Browse files
authored
Solution to LeetCode problem: 287 (#38)
* Added Solution to problem 287 Signed-off-by: Amisha Sahu <[email protected]> * added time & space complexity * Updated the code spacing and complexity. * Update Solution.cpp
1 parent f1e6957 commit 4ec24ba

File tree

1 file changed

+16
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)