Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import java.util.*;
  2. import java.lang.*;
  3.  
  4. public class RemoveAdjacent {
  5. public static void main(String[] args) {
  6. InputStreamReader isr = new InputStreamReader(System.in);
  7. BufferedReader br = new BufferedReader(isr);
  8. String s = "geeksforgeeks";
  9. removeDuplicate(s, 0);
  10. }
  11.  
  12. public static void removeDuplicate(String d, int i) {
  13. int n = d.length();
  14. if (d.charAt(i) == d.charAt(i + 1) && i <= n) {
  15. d = d.substring(0, i) + d.substring(i + 1, n + 1);
  16. i = i + 1;
  17. removeDuplicate(d, i);
  18. } else if (i <= n) {
  19. i = i + 1;
  20. removeDuplicate(d, i);
  21. } else {
  22. System.out.println(d);
  23. return;
  24. }
  25. }
  26. }
  27.  
  28. at java.lang.String.substring(String.java:1963)
  29. String.java:1963
  30. at RemoveAdjacent.removeDuplicate(RemoveAdjacent.java:16)
  31. RemoveAdjacent.java:16
  32. at RemoveAdjacent.removeDuplicate(RemoveAdjacent.java:21)
  33. RemoveAdjacent.java:21
  34. at RemoveAdjacent.main(RemoveAdjacent.java:10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement