返回字符串中第一个只出现一次的字符

返回字符串中第一个只出现一次的字符,若无则返回空格。

class Solution
{
  public:
  char firstUniqueChar(string s)
  {
    unordered_map<char,int> m;
    for(auto e: s)
    {
       m[e]++;
    }
    for(auto e: s)
    {
      if(m[e]==1) return e;
    }
    return ' ';
  }
};
发布了22 篇原创文章 · 获赞 1 · 访问量 334

猜你喜欢

转载自blog.csdn.net/weixin_43086349/article/details/104691871