class Solution
{
private:
vector<int> arr; //也可以用剑指offer第2版P247的处理方式
string s;
public:
Solution() : arr(256)
{
}
//Insert one char from stringstream
void Insert(char ch)
{
char temp[] ={'\0','\0'};
temp[0]=ch;
s = s + ch;
arr[int(ch)] += 1;
}
//return the first appearence once char in current stringstream
char FirstAppearingOnce()
{
int n=s.size();
for (int i=0; i<n; i++)
{
if (arr[int(s[i])] == 1)
return s[i];
}
return '#';
}
};
剑指offer面试题50题目2--类中private数据成员用vector容器的处理方式
最新推荐文章于 2024-04-25 16:34:09 发布