Turn!
Problem:
Given a string, such as a = "ABCDACD", to find the first occurrence of a character, in a, the first occurrence of a character is ' B '.
Analysis:
In order to determine whether a character appears once, we can traverse from the beginning, and if there is no repetition, then choose, otherwise discard. The complexity of doing so is O (n^2). In fact, the question of whether the existence or the number of occurrences of the problem, basically will be related to hastable, we can build an array of array[256] (ASCII), and then the string first processed, for each occurrence of the character, we can be in the corresponding position +1. In this way, we iterate through the string again from the beginning, and if we find that the number of characters is 1, the character is returned.
Reprint Please specify source: Http://blog.csdn.net/beiyeqingteng
Finds the first occurrence of a character in a string