题解 | #字符流中第一个不重复的字符#
字符流中第一个不重复的字符
https://www.nowcoder.com/practice/00de97733b8e4f97a3fb5c680ee10720
//Init module if you need var str =""; function Init() { // write code here } //Insert one char from stringstream function Insert(ch) { // write code here str +=ch; return str; } //return the first appearence once char in current stringstream let res =""; function FirstAppearingOnce() { // write code here let hash ={}; let flag = 1; for(let i = 0; i < str.length ; i++){ let key = str.charAt(i); if(!hash[key]) { hash[key] = 1; } else hash[key]++; } let keys = Object.keys(hash); for(let i = 0 ; i < keys.length ; i++){ if(hash[keys[i]]===1) { return keys[i]; } if(hash[keys[i]]!== 1){flag =0;} } if(flag === 0) return "#" } module.exports = { Init : Init, Insert : Insert, FirstAppearingOnce: FirstAppearingOnce };