Guest User

Untitled

a guest
Apr 7th, 2020
145
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2.     public int countElements(int[] arr) {
  3.         int counter = 0;
  4.         Arrays.sort(arr);
  5.         int tmp =1;
  6.         for (int i = 1; i <arr.length; i++) {
  7.             if(arr[i]==arr[i-1]) {
  8.                 tmp++;
  9.                 continue;
  10.             }
  11.             if(arr[i]==arr[i-1]+1){
  12.                 counter+=tmp;
  13.                 tmp=1;
  14.             }
  15.             tmp=1;
  16.         }
  17.         return counter;
  18.     }
  19. }
RAW Paste Data