Content-Length: 291862 | pFad | http://github.com/xiaoyu2er/leetcode-js/commit/555086b6554091dee62aa8974993785e2ee6b45f

86 add Easy_387_First_Unique_Character_in_a_String · xiaoyu2er/leetcode-js@555086b · GitHub
Skip to content

Commit 555086b

Browse files
author
zongyanqi
committed
add Easy_387_First_Unique_Character_in_a_String
1 parent 09d99f1 commit 555086b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.
3+
4+
Examples:
5+
6+
s = "leetcode"
7+
return 0.
8+
9+
s = "loveleetcode",
10+
return 2.
11+
Note: You may assume the string contain only lowercase letters.
12+
13+
14+
*/
15+
16+
/**
17+
* @param {string} s
18+
* @return {number}
19+
*/
20+
var firstUniqChar = function (s) {
21+
22+
for (var i = 0; i < s.length; i++) {
23+
var ch = s[i];
24+
if (s.lastIndexOf(ch) === s.indexOf(ch)) return i;
25+
}
26+
return -1;
27+
};
28+
29+
console.log(firstUniqChar('leetcode'));
30+
console.log(firstUniqChar('loveleetcode'));

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/xiaoyu2er/leetcode-js/commit/555086b6554091dee62aa8974993785e2ee6b45f

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy