Skip to content

Commit 81552a0

Browse files
committed
442. Find All Duplicates in an Array
1 parent c0d7980 commit 81552a0

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+
//https://leetcode.com/problems/find-all-duplicates-in-an-array/
2+
3+
class Solution {
4+
public:
5+
vector<int> findDuplicates(vector<int>& nums) {
6+
vector<int>result;
7+
for(int num : nums ){
8+
int index = abs(num);
9+
if(nums[index-1] < 0){
10+
result.push_back(index);
11+
}
12+
else nums[index-1]*=-1;
13+
}
14+
return result;
15+
}
16+
};

0 commit comments

Comments
 (0)