代码演示:
package swordfingeroffer
;
public class InterviewQuestion50 {
public int FirstNotRepeatingChar(String str
) {
if (null
== str
|| "".equals(str
)) {
return -1;
}
char[] chars
= str
.toCharArray();
int[] hashTable
= new int[256];
int n
= str
.length();
for (int i
= 0; i
< n
; i
++) {
int tmp
= chars
[i
];
hashTable
[tmp
] ++;
}
for (int i
= 0; i
< n
; i
++) {
if (hashTable
[chars
[i
]] == 1) {
return i
;
}
}
return 0;
}
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-58164.html