题解 | #字符流中第一个不重复的字符#
字符流中第一个不重复的字符
https://www.nowcoder.com/practice/00de97733b8e4f97a3fb5c680ee10720
const singleArray: { value: string; count: number } [] = []
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param ch string字符串型
* @return 无
*/
export function Insert(ch: string) {
// write code here
const index = singleArray.findIndex(({ value }) => value === ch)
if (index === -1) {
singleArray.push({ value: ch, count: 1 })
} else {
singleArray[index].count++
}
}
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param 无
* @return string字符串型
*/
export function FirstAppearingOnce(): string {
// write code here
const index = singleArray.findIndex(({ count }) => count === 1)
if (index === -1) {
return '#'
} else {
return singleArray[index].value
}
}

查看6道真题和解析