remove duplicate characters in a string
2022年5月1日小于 1 分钟
remove duplicate characters in a string
Question
Given a string, write a function to remove the duplicate characters to make sure that each character only occurs once.
For example
'xyzabcxyzabc'
Each character appears twice, we could make it unique as follows
'xyzabc'
'xyabcz'
'xabcyz'
'abcxyz'
'abxyzc'
.....
Above all substrings subsequences (*) contains unique characters, but you need to return the smallest one in lexicographical order( 'a' -> 'z'), which is 'abcxyz'
.
All input only contains valid lowercase alphabets only.
Code
/**
* @param {string} str
* @return {string}
*/
function smallestUniqueSubstr(str) {
// your code here
}