标签:hashtable 1.7 public not clu 描述 std font 数组
1 #include <iostream> 2 #include <string> 3 using namespace std; 4 class Solution { 5 public: 6 int FirstNotRepeatingChar(string str) { 7 int length = str.size(); 8 if(length <= 0) 9 return -1; 10 const int hashSize = 256; 11 unsigned int hashTable[hashSize] = {0}; 12 for(int i=0;i<length;i++) 13 { 14 hashTable[str[i]]++; 15 } 16 int i=0; 17 while(str[i] != ‘\0‘) 18 { 19 if(hashTable[str[i]] == 1) 20 return i; 21 i++; 22 } 23 return -1; 24 } 25 }; 26 27 int main() 28 { 29 string s = "abaccdeff"; 30 Solution ss; 31 int r; 32 r = ss.FirstNotRepeatingChar(s); 33 cout<<r<<endl; 34 return 0; 35 }
标签:hashtable 1.7 public not clu 描述 std font 数组
原文地址:http://www.cnblogs.com/qqky/p/6964840.html