Menu

Produce a method that removes all the duplicate letters from the input string and returns the unique characters in sorted order. The method shouldn’t distinguish between upper and lower case character…

Question

Answered step-by-step

Produce a method that removes all the duplicate letters from the…

Produce a method that removes all the duplicate letters from the input string and returns the unique characters in sorted order. The method shouldn’t distinguish between upper and lower case characters and must take O(n log n) time. All the characters in the output should be in lowercase. Call this method: removeDuplicates

Parameter(s): String

Returns: String

Ex. Input: “zzyxAaabBbcD”, Output: “abcdxyz”

 

This is my answer so far, I just need help finishing the code:

 

 

import java.util.*;
import java.util.ArrayList;

class Main {
 public static void main(String[] args) {
   String input =”zzyxAaabBbcD”;
   System.out.println(removeDuplicates(input));

 }
 
 public static String removeDuplicates (String x){
   String removeduplicates = “”;
   String output = x.toLowerCase ();
   for (int i = 0; i<output.length;i++){
     if(!removeduplicates.contains(String.valueOf(output.charAt(i)))){
       
       }
     }
   return removeDuplicates;
         
   }

     
}

 

 

 

OR

Leave a Reply

Your email address will not be published. Required fields are marked *