Skip to content

387. 字符串中的第一个唯一字符 #35

Open
@zpc7

Description

@zpc7

387. 字符串中的第一个唯一字符

/**
 * @param {string} s
 * @return {number}
 */
var firstUniqChar = function (s) {
    const map = new Map();
    for (let i = 0; i < s.length; i++) {
        map.set(s[i], (map.get(s[i]) || 0) + 1);
    }
    for (let index = 0; index < s.length; index++) {
        if (map.get(s[index]) === 1) {
            return index
        }
    }
    return -1;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    简单LeetCode 难度定级

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions