Skip to content

Instantly share code, notes, and snippets.

@Nut
Created May 19, 2015 18:34
Show Gist options
  • Save Nut/25fe37049afeed35d7f9 to your computer and use it in GitHub Desktop.
Save Nut/25fe37049afeed35d7f9 to your computer and use it in GitHub Desktop.
package algo.task;
public class Task4 {
public static void main(String[] args) {
int[] test = {1, 2, 3, 1, 5, 2, 4};
findDuplicates(test);
}
public static void findDuplicates(int array[]) {
for (int i = 0; i < array.length; i++) {
if (array[Math.abs(array[i])] >= 0) {
array[Math.abs(array[i])] *= -1;
} else {
System.out.println("Duplicate: " + Math.abs(array[i]));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment