Skip to content

Commit

Permalink
Datastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
sunil committed Sep 12, 2019
1 parent 7e5dd07 commit 1877ecd
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ public static void main(String[] args) {

// Function to print duplicates
void printRepeating(int arr[]) {
System.out.println("The repeating elements are : ");
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i] + " : " + Math.abs(arr[i]));
if (arr[Math.abs(arr[i])] >= 0) {
arr[Math.abs(arr[i])] = -arr[Math.abs(arr[i])];

int index = Math.abs(arr[i]);
if (arr[index] < 0) {
System.out.println("Duplicate found " + Math.abs(arr[i]));
} else {
System.out.print(Math.abs(arr[i]) + " ");
arr[index] = -arr[index];
}

}
}

Expand Down

0 comments on commit 1877ecd

Please sign in to comment.