Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

字符流中第一个不重复的字符 #23

Open
fengguangpei opened this issue Feb 22, 2021 · 0 comments
Open

字符流中第一个不重复的字符 #23

fengguangpei opened this issue Feb 22, 2021 · 0 comments

Comments

@fengguangpei
Copy link

function FirstAppearingOnce() {
let minIndex = 256;
let strIndex = 0;
for (let i = 0; i < 256; i++) {
if (container[i] >= 0 && container[i] < minIndex) {
minIndex = container[i];
strIndex = i;
}
}
return minIndex === 256 ? '#' : String.fromCharCode(strIndex);
}

container[i] >= 0时,container[i]对应字符在字符串中的下标,所以实际使用时 minIndex = [传入的字符串长度或者无穷大]。
哈哈哈,当然这里不涉及具体问题,思路正确。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant