C++ kinds of topo sort


  • 0
    L

    '''
    class Solution {
    public:
    string originalDigits(string s) {
    unordered_map<char, int> mapping;
    for (auto c : s) mapping[c]++;
    vector<string> digits{ "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };

        string order("zwgxufvoih");
        vector<int> indexes{ 0, 2, 8, 6, 4, 5, 7, 1, 9, 3 };
        string ret;
        for (int i = 0; i < order.size(); i++)
        {
            char o = order[i];
            while (mapping[o] != 0)
            {
                for (auto c : digits[indexes[i]])
                {
                    mapping[c]--;
                }
                ret+=to_string(indexes[i]);
            }
        }
        std::sort(ret.begin(), ret.end());
        return ret;
    }
    

    };''


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.