Advertisement
Guest User

Untitled

a guest
May 19th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. public static void main(String[] args) {
  2. int[] A = {3,5,6,3,3,5};
  3. int[] B = {-1000000000,3,5,6,-1000000000};
  4. int[] C = new int[0];
  5.  
  6. System.out.println(solution(A));
  7. System.out.println(solution(B));
  8. System.out.println(solution(C));
  9. }
  10.  
  11. private static int solution(int[] A){
  12. int counter = 0;
  13. if(A.length == 1){
  14. return 0;
  15. }
  16. for( int index = 0; index < A.length; index++) {
  17. int currentToCheck = A[index];
  18.  
  19. for (int j = 1; j < A.length; j++) {
  20. if (index < j && currentToCheck == A[j]) {
  21. counter++;
  22. }
  23. }
  24. }
  25. return counter;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement