2023-08-07力扣今日八题

链接:

剑指 Offer 50. 第一个只出现一次的字符

题意:

如题

解:

map存下标,由于存在下标0,所以用find,或者记录下标+1也可以

实际代码:

#include
using namespace std;
char firstUniqChar(string s)
{
    mapmp;
    for(int i=0;i=s.length()) return ' ';
    return s[index];
}
int main()
{
    string s;cin>>s;
    char ans=firstUniqChar(s);
    cout<

限制:

  • 0 <= s 的长度 <= 50000

你可能感兴趣的:(力扣每日一题,leetcode,算法)