Skip to content

Instantly share code, notes, and snippets.

@thmain
Created August 26, 2017 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thmain/18d81c7fcf290b0fe30d0108ef7bec7e to your computer and use it in GitHub Desktop.
Save thmain/18d81c7fcf290b0fe30d0108ef7bec7e to your computer and use it in GitHub Desktop.
public class EveryElementsRepeatedButOne {
public static void findBruteForce(int [] a){
boolean [] visited = new boolean[a.length];
for (int i = 0; i <a.length ; i++) {
int x = a[i];
if(visited[i]==false) {
boolean isDuplicate = false;
for (int j = i + 1; j < a.length; j++) {
if (x == a[j]) {
isDuplicate = true;
visited[j] = true;
}
}
if (!isDuplicate)
System.out.println("Element appear only once in array - " + x);
}
}
}
public static void main(String[] args) {
int [] a = { 1,5,6,2,1,6,4,3,2,5,3};
findBruteForce(a);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment