Skip to content

Commit 36e6f97

Browse files
authored
Create FFFro.md
1 parent 40a843f commit 36e6f97

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

2018.12.1-leetcode387/FFFro.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
public class Solution {
2+
public int FirstNotRepeatingChar(String str) {
3+
if (str.length() == 0)
4+
return -1;
5+
int index = 1;
6+
int[] temp = new int[26];
7+
for (int i = 0; i < str.length(); i++) {
8+
int a = (int)str.charAt(i) - 97;
9+
if (temp[a] == 0){
10+
temp[a] = index++;
11+
}else {
12+
temp[a] = -1;
13+
}
14+
}
15+
char c = '#';
16+
int res= Integer.MAX_VALUE;
17+
for (int j = 0; j < temp.length; j++) {
18+
if (temp[j] > 0){
19+
if (temp[j] < res){
20+
res = temp[j];
21+
c = (char) (j+97);
22+
}
23+
}
24+
}
25+
if (c == '#'){
26+
return -1;
27+
}
28+
for (int k = 0; k < str.length(); k++) {
29+
if (str.charAt(k) == c){
30+
return k;
31+
}
32+
}
33+
return -1;
34+
}
35+
36+
37+
}

0 commit comments

Comments
 (0)