Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Solution_Arrays{
- public int solution(int [] A) {
- int value =0;
- int counter=0;
- for(int i=0; i<A.length; i++) {
- if(A[i]==0) continue;
- value = A[i];
- for(int j=i+1; j<A.length;j++) {
- if(value==A[j]) {
- A[j]=0;
- counter++;
- }
- }
- if(counter==0) break;
- }
- return value;
- }
- public static void main(String[] args) {
- int arrayOfOds[] = new int[7];
- arrayOfOds[0]= 9;
- arrayOfOds[1]= 3;
- arrayOfOds[2]= 9;
- arrayOfOds[3]= 3;
- arrayOfOds[4]= 9;
- arrayOfOds[5]= 7;
- arrayOfOds[6]= 9;
- Solution_Arrays forUse = new Solution_Arrays();
- System.out.println("Your number of single occurence " + forUse.solution(arrayOfOds));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement