The title of the sword refers to the offer face question 55
New Ket Network test address: https://www.nowcoder.com/questionTerminal/00de97733b8e4f97a3fb5c680ee10720
The first character in a character stream that does not repeat the heat index: 26323 time limit: 1 seconds space limit: 32768K Please implement a function to find the first character in the character stream that appears only once. For example, when you read only the first two characters "go" from the character stream, the first character that appears only once is "G". When you read the first six characters, "Google," from the stream of characters, the first character that appears only once is "L".
Output Description:
Returns the # character if the current character stream does not exist with a single occurrence.
The Java code is as follows:
Package go.jacob.day531;
public class Demo3 {
//character range (after turning int): -128~127
int[] hash=new int[256];
StringBuilder sb=new StringBuilder ();
Insert one char from StringStream public
void Insert (char ch) {
hash[ch+128]++;
Sb.append (CH);
}
Return the ' the ' the ' appearence once char in ' stringstream public
char firstappearingonce () {for
(char S:SB . toString (). ToCharArray ())
if (hash[s+128]==1) return
s;
Return ' # ';
}
}