index(STRING, SUBSTRING, POSITION) -- Returns the position of the first occurrence of SUBSTRING in STRING at or after POSITION. If you don't specify POSITION, the search starts at the beginning of STRING
You'll be looking for the first occurrence of the CURRENT character in the string AFTER the current position. Any way you look at it, it is O(n^2) on the length of your string. At least this solution doesn't use additional memory like the solution with the hash.
Actually, the hash based solution is roughly O(length) time. It's (approximately) a constant amount of time to insert/index into the hash, and you only iterate over the string once.