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

题目描述

在字符串 s 中找出第一个只出现一次的字符。如果没有,返回一个单空格。 s 只包含小写字母。

示例:

s = "abaccdeff"
返回 "b"
s = "" 
返回 " "

限制:

0 <= s 的长度 <= 50000

来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof

代码实现

class Solution {
public:
      char firstUniqChar(string s) {
            if(s.length() == 0)
                  return ' ';
            map<char, int> cmap;
            for(int i = 0; i < s.length(); i++)
                  cmap[s[i]]++;
            for(int i = 0; i < s.length(); i++)
                  if(cmap[s[I]] == 1)
                        return s[I];
            return ' ';
      }
}
原文地址:https://www.cnblogs.com/xqmeng/p/13616411.html