JZ34-第一个只出现一次的字符位置
第一个只出现一次的字符
https://www.nowcoder.com/practice/1c82e8cf713b4bbeb2a5b31cf5b0417c?tpId=13&tqId=11187&rp=1&ru=%2Fta%2Fcoding-interviews&qru=%2Fta%2Fcoding-interviews%2Fquestion-ranking&tab=answerKey
class Solution2 { public int FirstNotRepeatingChar(String str) { if (str == null || str.length() == 0) { return -1; } int[] temp = new int[256]; for (int i = 0; i < str.length(); i++) { temp[str.charAt(i)]++; //把e对应的第97个位置的数字+1。。。 } for (int i = 0; i < str.length(); i++) { if (temp[str.charAt(i)] == 1) { //求e对应的数组位置上的数值 str.charAt(i)从头开始遍历字符 return i; } } return -1; } }