Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion ArraysSolutions/Find All Duplicates in an Array.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Solution of Find All Duplicates in an Array

### First Approach

#### Time Complexity - O (n)

#### Space Complexity - O(1)
Expand Down Expand Up @@ -39,7 +41,35 @@ return list;
}

```
### Second Approach

#### Time Complexity - O (n)

#### Space Complexity - O(1)

```java
class Solution {
public List<Integer> findDuplicates(int[] nums) {
List <Integer> list = new ArrayList <Integer>();
int n = nums.length;
int index;
for (int i = 0 ; i < n; i++){
int num = nums[i];
index = Math.abs(num) - 1 ;
if ( nums[index] < 0){
list.add(Math.abs(nums[i]));
}
else{
nums[index] = nums[index] * -1;
}
}
return list;
}
}

```


<div align="right">
Contributed By <a href="https://github.com/rath23"> Muneer Ahmad</a>
</div>
</div>