Created
August 26, 2017 17:53
-
-
Save thmain/18d81c7fcf290b0fe30d0108ef7bec7e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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