387.字符串中的第一个唯一字符
题目链接
static const auto io_speed_up = [](){
ios::sync_with_stdio(false);
cin.tie(0);
return 0;
}();
class Solution {
public:
int firstUniqChar(string s) {
int f[26]={0};
for(char p : s)f[p-'a']++;
for(int i = 0; i < s.size(); i++)if(f[s[i]-'a']==1)return i;
return -1;
}
};
389.找不同
题目链接
class Solution {
public:
char findTheDifference(string s, string t) {
char ans = 0;
for(char p : s)ans ^= p;
for(char p : t)ans ^= p;
return ans;
}
};