Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.lang.*;
- public class RemoveAdjacent {
- public static void main(String[] args) {
- InputStreamReader isr = new InputStreamReader(System.in);
- BufferedReader br = new BufferedReader(isr);
- String s = "geeksforgeeks";
- removeDuplicate(s, 0);
- }
- public static void removeDuplicate(String d, int i) {
- int n = d.length();
- if (d.charAt(i) == d.charAt(i + 1) && i <= n) {
- d = d.substring(0, i) + d.substring(i + 1, n + 1);
- i = i + 1;
- removeDuplicate(d, i);
- } else if (i <= n) {
- i = i + 1;
- removeDuplicate(d, i);
- } else {
- System.out.println(d);
- return;
- }
- }
- }
- at java.lang.String.substring(String.java:1963)
- String.java:1963
- at RemoveAdjacent.removeDuplicate(RemoveAdjacent.java:16)
- RemoveAdjacent.java:16
- at RemoveAdjacent.removeDuplicate(RemoveAdjacent.java:21)
- RemoveAdjacent.java:21
- at RemoveAdjacent.main(RemoveAdjacent.java:10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement