用可以使用整型数组来保存字符x出现的次数
public class Test {
public static void main(String[] args) {
String s="google";
Test t=new Test();
System.out.println(t.FirstNotRepeatingChar(s)+1);
}
public int FirstNotRepeatingChar(String str) {
int[] cnts = new int[256];
for (int i = 0; i < str.length(); i++)
cnts[str.charAt(i)]++;
for (int i = 0; i < str.length(); i++)
if (cnts[str.charAt(i)] == 1)
return i;
return -1;
}
}