Simple using map in o(n) and o(n) extra space


#1

int Solution::anytwo(string A) {
unordered_map<char,vector > m;
string s;
for(int i=0;i<A.length();i++){
m[A[i]].push_back(i);
if(m[A[i]].size()>=3){
return 1;
}
}
for(int i=0;i<A.length();i++){
if(m[A[i]].size()==2){
s=s+A[i];
}
}
//cout<<s<<endl;
int i=0,j=s.length()-1;
while(i<j){
if(s[i]!=s[j]){
return 1;
}
else{
i++;
jā€“;
}
}
return 0;
}
Comment body goes here.