File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public int firstUniqChar(String s) {
3
+ char[ ] storeArr = new char[ 26] ;//暂时存储数组,根据出现的顺序
4
+ int[ ] numArr = new int[ 26] ;//存储数目
5
+
6
+ char[] sArr = s.toCharArray();
7
+ int len = sArr.length;
8
+ for (int i=0;i<len;i++){
9
+ for (int j=0;j<26;j++){
10
+ if (storeArr[j] == 0){
11
+ storeArr[j] = sArr[i];
12
+ numArr[j]=1;
13
+ break;
14
+ }
15
+ if (storeArr[j] == sArr[i]){
16
+ numArr[j] += 1;
17
+ break;
18
+ }
19
+ }
20
+ }
21
+ int temp = -1;
22
+ for (int i =0;i<26;i++){
23
+ if (numArr[i]==1){
24
+ temp = i;
25
+ break;
26
+ }
27
+ }
28
+ int result = 0;
29
+ if (temp == -1)
30
+ return -1;
31
+ else {
32
+ for (int i = 0;i<len;i++){
33
+ if (storeArr[temp]== sArr[i]){
34
+ result = i;
35
+ break;
36
+ }
37
+ }
38
+ }
39
+ return result;
40
+ }
41
+ }
You can’t perform that action at this time.
0 commit comments