Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit555086b

Browse files
author
zongyanqi
committed
add Easy_387_First_Unique_Character_in_a_String
1 parent09d99f1 commit555086b

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+
varfirstUniqChar=function(s){
21+
22+
for(vari=0;i<s.length;i++){
23+
varch=s[i];
24+
if(s.lastIndexOf(ch)===s.indexOf(ch))returni;
25+
}
26+
return-1;
27+
};
28+
29+
console.log(firstUniqChar('leetcode'));
30+
console.log(firstUniqChar('loveleetcode'));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp