求助大佬们,全局变量报错,私有变量通过了
以下两个变量声明为全局变量,就报错了 vector<int> v; int alpha[130];
这样声明就错了 private: vector<int> v; int alpha[130];
可我在本地,我测试了很多,结果都一样的!!
以下的是通过的,取消注释就通过不了了。。
题目:字符流中第一个不重复的字符
//vector<int> v;
//int alpha[130];
class Solution {
private:
vector<int> v;
int alpha[130];
public:
void Insert(char ch) {
alpha[ch] += 1;
if(alpha[ch] == 1) {
v.push_back(ch);
} else if(alpha[ch] == 2) {
int len = v.size();
for(vector<int>::iterator it = v.begin(); it != v.end(); it++) {
if(*it == ch) {
v.erase(it);
break;
}
}
}
}
char FirstAppearingOnce() {
int len = v.size();
if(len == 0) return '#';
else return v[0];
}
}; 