前端算法之重复字符串
function fn(str) {
let obj = {};
let temp = null
for (let i = 0; i < str.length; i++) {
temp = str[i];
if (obj[temp]) {
obj[temp] = obj[temp] + 1;
} else {
obj[temp] = 1;
}
}
console.log(obj);
let result = [];
for (let i = 0; i < str.length; i++) {
temp = str[i];
if (obj[temp] === 1) {
result.push(temp);
} else {
result.push("#");
}
}
console.log(result.join(''));
}
fn("google");

浙公网安备 33010602011771号