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.  
  14. System.out.println(removeDuplicates(arr));
  15. }
  16.  
  17. static int removeDuplicates(int[] nums) {
  18. int n = nums.length;
  19.  
  20. int k =0;
  21. for(int i = 0 ;i<n;i++){
  22. boolean check = false;
  23.  
  24. for(int j = 0;j < i;j++){
  25. if(nums[i] == nums[j]){
  26. check = true;
  27. break;
  28. }
  29. }
  30.  
  31.  
  32. if(!check){
  33. nums[k] = nums[i];
  34. k++;
  35. }
  36. }
  37. return k;
  38. }
  39. }
Success #stdin #stdout 0.08s 52580KB
stdin
Standard input is empty
stdout
5