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

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

Open
zpc7 opened this issue Aug 17, 2022 · 0 comments
Open

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

zpc7 opened this issue Aug 17, 2022 · 0 comments
Labels
简单 LeetCode 难度定级

Comments

@zpc7
Copy link
Owner

zpc7 commented Aug 17, 2022

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;
};
@zpc7 zpc7 added the 简单 LeetCode 难度定级 label Aug 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
简单 LeetCode 难度定级
Projects
None yet
Development

No branches or pull requests

1 participant