找出字符串中第一个只出现一次的字符
2020-07-12 本文已影响0人
天黑就拉登



while(str = readline()){
let obj = {};
let arr = [];
for(let i=0;i<str.length;i++){
if(!obj.hasOwnProperty(str[i])){
obj[str[i]] = 1;
}else{
obj[str[i]]++;
}
}
for(let j in obj){
if(obj[j] == 1){
arr.push(j)
}
}
console.log(arr.length>0?arr[0]:'-1')
}