字符流中第一个不重复的字符c++

使用一个hash和字符串来记录过程

class Solution
{
public:
	map<char, int>M;
	string s="";
	//Insert one char from stringstream
	void Insert(char ch)
	{
		s += ch;
		M[ch]++;
	}
	//return the first appearence once char in current stringstream
	char FirstAppearingOnce()
	{
		for (int i = 0; i < s.size();i++)
		if (M[s[i]] == 1)return s[i];
		return '#';
	}

};

你可能感兴趣的:(剑指offer题,剑指offer)