将字符串转换为新字符串,其中如果该字符在原始字符串中仅出现一次,则新字符串中的该字符替换为“(”,如果该字符在原始字符串中多次出现,则替换为“)” 。 在确定字符是否重复时忽略大小写。
example:
"din" => "((("
"recede" => "()()()"
"Success" => ")())())"
"(( @" => "))(("
代码:
function duplicateEncode(word){
var lowWord = word.toLowerCase();
var result = [];
for(var i in lowWord){
var temp = lowWord.split(lowWord[i]);
if(temp.length > 2){
result.push(")");
}else{
result.push("(");
}
}
return result.join('');
}