Problem Statement
You are given a String S of lowercase English letters.
Some of the letters may occur multiple times in S. For example, there are three 'a's and two 'n's in "banana".
You dislike duplicates. For each letter, you want to keep only its first occurrence and delete all the others. Return the String obtained from S by deleting the duplicates of each letter, as described above.
Definition
- Class:
- Unique
- Method:
- removeDuplicates
- Parameters:
- String
- Returns:
- String
- Method signature:
- String removeDuplicates(String S)
- (be sure your method is public)
Constraints
- S will contain between 1 and 1000 characters, inclusive.
- Each character of S will be a lowercase English letter ('a'-'z').
Examples
"banana"
Returns: "ban"
"aardvark"
Returns: "ardvk"
"xxxxx"
Returns: "x"
"topcoder"
Returns: "topcder"