The title of the sword refers to the offer face question 35
New Ket Network test address: https://www.nowcoder.com/questionTerminal/1c82e8cf713b4bbeb2a5b31cf5b0417c
Time limit: 1 seconds space limit: 32768K algorithm Knowledge video tutorial finds the first occurrence of a character in a string (1<= string length <=10000, all composed of letters) and returns its position. If the string is empty, return-1
Package go.jacob.day509;
/* * Character char range is 128 to 127, not just A-Z
/public class Demo2 {public
int Firstnotrepeatingchar (String str) {
if (str = NULL | | str.equals (""))
return-1;
char[] chars = Str.tochararray ();
int[] arr = new int[256];
for (int i = 0; i < chars.length i++)
Arr[hash (chars[i))]++;
int index = 0;
for (int i = 0; i < chars.length i++) {
if (Arr[hash (chars[i))] = = 1) {
index = i;
break;
}
}
return index;
}
Creates a hash map for the character, the subscript private int hash of the mapped array
(char c) {return
C + 128;
}
}