leetcode269

class Solution {
public:
    string alienOrder(vector &words) {
        unordered_map> mp;unordered_map in;
        unordered_set dic;
        string temp;
        for(int i=0;i,greater>q;temp="";
        for(char i='a';i<='z';++i)if(in[i]==1)q.push(i);
        while(!q.empty()){
            char x=q.top();
            q.pop();temp+=x;
            for(auto &p:mp[x])if(--in[p]==1)q.push(p);
        }
        if(temp.size()!=dic.size())temp="";
        return temp;
    }
};

你可能感兴趣的:(leetcode269)