LC 1585. Check If String Is Transformable With Substring Sort Operations

link

class Solution {
public:
    bool isTransformable(string s, string t) {
        vector<deque<int>> pos(10);
        for(int i=0;i<s.size();i++){
            pos[s[i]-'0'].push_back(i);
        }
        for(char c:t){
            if(pos[c-'0'].empty()) return false;
            for(int i=0;i<c-'0';i++){
                if(!pos[i].empty() && pos[i].front()<pos[c-'0'].front()) return false;
            }
            pos[c-'0'].pop_front();
        }
        return true;
    }
};
posted @ 2020-09-15 08:23  feibilun  阅读(71)  评论(0编辑  收藏  举报