字符流中的第一个不重复的字符
2023/2/11小于 1 分钟
字符流中的第一个不重复的字符
题目链接
题目描述
刷题思路
代码实现
/*
* @Description: 【中等】字符流中的第一个不重复的字符
* @Version: Beta1.0
* @Author: 微信公众号:储凡
* @Date: 2021-04-29 21:40:02
* @LastEditors: 微信公众号:储凡
* @LastEditTime: 2021-04-29 21:47:24
*/
// Init module if you need
let result
export function Init() {
result = ''
}
// Insert one char from stringstream
export function Insert(ch) {
result += ch
return result
}
// return the first appearence once char in current stringstream
export function FirstAppearingOnce() {
for (let index = 0; index < result.length; index++) {
//
const str = result[index]
// 注意这里遍历,str字符要么只有一个,不存在找不到为-1的情况,因为str从字符中截取的
if (result.indexOf(str) === result.lastIndexOf(str)) {
return str
}
}
// 没有返回
return '#'
}
一些建议
更新日志
2024/7/28 10:06
查看所有更新日志
c0f2d
-于06596
-于9b9e4
-于b0275
-于5f1e1
-于2b8a3
-于02ab1
-于8de1a
-于d0347
-于ced18
-于a23ce
-于80f08
-于e34c0
-于74aa9
-于3c22c
-于9bbe9
-于e4c74
-于