C++ O(n) easy to understand
firstly let\'s consider the smallest char in s. eg, \'0\'\nto transerform, two condition must be satisfied:\n    1) the number of \'0\' in s must match the numb
firstly let\'s consider the smallest char in s. eg, \'0\'\nto transerform, two condition must be satisfied:\n    1) the number of \'0\' in s must match the number of \'0\' in t.\n    2) the positions of \'0\' in t must be less or equal to it in s. since \'0\' can only move to left, not right. \nif s, t, \'0\' satisfied the two condition, I remove all the \'0\' in s and \'t\'.  and check \'1\' next. and \'2\', \'3\'... one by one.   \n\n```\nclass Solution {\npublic:\n    bool isTransformable(string s, string t) {\n        for(char c = \'0\'; c<=\'9\'; c++){\n            if(!verifyAndReduce(s, t, c)) return false;\n        }\n        return true;\n    }\n    \n    bool verifyAndReduce(string& s, string& t, char c){\n        if(count(s.begin(), s.end(), c) != count(t.begin(), t.end(), c)) return false;\n        queue<int> index;\n        for(int i=0;i<s.size();i++) if(s[i] == c) index.push(i);\n        for(int i=0;i<t.size();i++) {\n            if(t[i] == c){\n                auto j = index.front(); index.pop();\n                if(j < i) return false;\n            }\n        }\n        s.erase(remove(s.begin(), s.end(), c), s.end());\n        t.erase(remove(t.begin(), t.end(), c), t.end());\n        return true;\n    }\n};
[]