因为有大写字母所以不能只申请26空间
class Solution { public: int FirstNotRepeatingChar(string str) { vector<int> cnt(58, 0); for (auto &i: str) { cnt[i - 'A']++; } for (int i = 0; i < str.length(); i++) { if (cnt[str[i] - 'A'] == 1) return i; } return -1; } };
因为有大写字母所以不能只申请26空间
class Solution { public: int FirstNotRepeatingChar(string str) { vector<int> cnt(58, 0); for (auto &i: str) { cnt[i - 'A']++; } for (int i = 0; i < str.length(); i++) { if (cnt[str[i] - 'A'] == 1) return i; } return -1; } };