C++ Solution using STL


  • 0

    class Solution {
    public:
    vector<int> findPermutation(string s) {

        int size = s.length()+1;
        vector<int> vec(size);
        for(int i=1;i<=size;i++)
            vec[i-1] = i;
        
        int i=0,j;
        size--;
        while(i<size)
        {
            if(s[i] == 'D')
            { 
                j = i;
                while(s[j] == 'D'){
                    j++;
                }
                reverse(vec.begin()+i,vec.begin()+j+1);
                i = j;
            }
            else
                i++;
        }
        return vec;
    }
    

    };


Log in to reply
 

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