题解 | #找出字符串中第一个只出现一次的字符#
找出字符串中第一个只出现一次的字符
http://www.nowcoder.com/practice/e896d0f82f1246a3aa7b232ce38029d4
while(line = readline()) {
const arr = line.split('');
let result = arr.reduce((temp, data) => {
temp[data] = temp[data] ? temp[data] + 1 : 1;
return temp;
}, {})
let status = false;
for (let index in result) {
if (result[index] == 1) {
status = true;
print(index);
break;
}
}
if (!status) {
print(-1);
}
}