fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int[] arr = {0,0,1,1,1,2,2,3,3,4};
  13. System.out.println(unique(arr));
  14.  
  15. }
  16.  
  17. static int unique(int[] nums){
  18. int n = nums.length;
  19. int j = 1;
  20. int i = 0;
  21. while(j < n){
  22.  
  23. if(nums[j]!= nums[i]){
  24. i++;
  25. nums[i] = nums[j];
  26. }
  27. j++;
  28. }
  29. return i+1;
  30. }
  31. }
Success #stdin #stdout 0.12s 54588KB
stdin
Standard input is empty
stdout
5