Skip to content

Commit 432d897

Browse files
committed
Time: 40 ms (23.75%), Space: 58.4 MB (84.3%) - LeetHub
1 parent bf29c9e commit 432d897

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @param {string} s
3+
* @return {number}
4+
*/
5+
var firstUniqChar = function(s) {
6+
const map = new Map()
7+
for(let i = 0;i < s.length;i++){
8+
const currentChar = s[i]
9+
const count = map.get(currentChar) ?? 0
10+
map.set(currentChar, count + 1)
11+
}
12+
for(let i = 0;i < s.length;i++){
13+
const currentChar = s[i]
14+
const count = map.get(currentChar) ?? 0
15+
if(count == 1) return i
16+
}
17+
return -1
18+
};

0 commit comments

Comments
 (0)