Skip to content

Commit f832ec7

Browse files
committed
Add solution #387
1 parent 80fd026 commit f832ec7

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* 387. First Unique Character in a String
3+
* https://leetcode.com/problems/first-unique-character-in-a-string/
4+
* Difficulty: Easy
5+
*
6+
* Given a string, find the first non-repeating character in
7+
* it and return it's index. If it doesn't exist, return -1.
8+
*/
9+
10+
/**
11+
* @param {string} s
12+
* @return {number}
13+
*/
14+
var firstUniqChar = function(s) {
15+
for (let i = 0; i < s.length; i++) {
16+
if (s.indexOf(s.charAt(i)) === s.lastIndexOf(s.charAt(i))) {
17+
return i;
18+
}
19+
}
20+
21+
return -1;
22+
};

0 commit comments

Comments
 (0)