1. 其实就是map (key,value)
class Solution { public: int FirstNotRepeatingChar(string str) { map<char, int> mp; for(int i = 0; i < str.size(); ++i) mp[str[i]]++; for(int i = 0; i < str.size(); ++i){ if(mp[str[i]]==1) return i; } return -1; } };
原文地址:https://www.cnblogs.com/cgy1012/p/11403128.html
时间: 2024-10-13 15:47:36