Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
528 B
2
Indexable
Never
#include<map>
#include<queue>
class Solution {
	public:
		string FirstNonRepeating(string A){
		    map<char,int> visited;
		    queue<char>q;
		    string ans;
		    for(auto i:A){
		        q.push(i);
		        visited[i]++;
		    
		        while(!q.empty()){
		            if(visited[q.front()]>1){
		                q.pop();
		            }else{
		                ans.push_back(q.front());
		                break;
		            }
		            if(q.empty()) ans.push_back('#');
		        }
		    }
		    return ans;
		}
};