fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. /* package codechef; // don't place package name! */
  4.  
  5. import java.util.*;
  6. import java.lang.*;
  7. import java.io.*;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Codechef
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. // your code goes here\
  15. char str[]={'a','a','b','b'};
  16.  
  17. removeDuplicates(str);
  18. }
  19. public static void removeDuplicates(char[] str) {
  20. if (str == null) return;
  21. System.out.println("input array is "+str[0]+str[1]+str[2]+str[3]);
  22. int len = str.length;
  23. if (len < 2) return;
  24.  
  25. int tail = 1;
  26.  
  27. for (int i = 1; i < len; ++i) {
  28. int j;
  29. for (j = 0; j < tail; ++j) {
  30. if (str[i] == str[j]) break; }
  31. if (j == tail) {
  32. str[tail] = str[i];
  33. ++tail;
  34. }
  35. }
  36. str[tail] = 0;
  37. System.out.println("final array is " +str[0]+str[1]+str[2]+str[3]);
  38. }
  39. }
  40.  
Success #stdin #stdout 0.1s 27756KB
stdin
Standard input is empty
stdout
input array is aabb
final array is abb