longest substring with unique characters
2022年5月1日小于 1 分钟
longest substring with unique characters
Question
Given a string, please find the longest substring that has no repeated characters.
If there are multiple result, any one substring is fine.
longestUniqueSubstr('aaaaa')
// 'a'
longestUniqueSubstr('abcabc')
// 'abc', or 'bca', or 'cab'
longestUniqueSubstr('a12#2')
// 'a12#'
Follow-up
What is the time & space cost of your solution ? Could you do it better?
Code
/**
* @param {string} str
* @return {string}
*/
function longestUniqueSubstr(str) {
// your code here
}