标签:
1 class Solution { 2 public: 3 int FirstNotRepeatingChar(string str) { 4 int len = str.length(); 5 if (len == 0) 6 { 7 return -1; 8 } 9 map<char,int> mm; 10 for (int i = 0;i < len ; ++i) 11 { 12 if (mm.count(str[i]) == 0) 13 { 14 mm[str[i]] = 1; 15 } 16 else 17 { 18 ++ mm[str[i]]; 19 } 20 } 21 22 for (int i = 0;i < len ; ++i) 23 { 24 if (mm[str[i]] == 1) 25 return i; 26 } 27 return -1; 28 } 29 };
标签:
原文地址:http://www.cnblogs.com/xiaoyesoso/p/5159154.html