-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Labels
Description
题目地址 https://leetcode-cn.com/problems/first-unique-character-in-a-string/
Hash Table
时间复杂度O(n) 空间复杂度O(n)
var firstUniqChar = function(s) {
let map = {};
for (let i = 0; i < s.length; i++) {
const c = s[i];
map[c] = map[c] !== undefined ? map[c] + 1 : 1;
}
for (let i = 0; i < s.length; i++) {
if (map[s[i]] === 1)
return i;
}
return -1;
};