Skip to content

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

Open
@fengguangpei

Description

@fengguangpei

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 = [传入的字符串长度或者无穷大]。
哈哈哈,当然这里不涉及具体问题,思路正确。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions