Posts

Showing posts with the label program3

Remove duplicates recursively

Eliminate the character and it's pair when they are same. Repeat it until there is no adjacent duplicates in the string Sample input:   aabcddceffgge Sample output: bccee b Code: import java.util.*; public class Program3 {        public static void removeDuplicates(StringBuilder s){                int len = s.length();         int i=0;                while(i<len-1){             if(s.charAt(i) == s.charAt(i+1)){                 s.delete(i, i+2);                 len-=2;             }             else{          ...