Simple Java solution


  • 0
    M
    public int[] findPermutation(String s) {
        int n = s.length();
        int[] res = new int[n+1];
        for(int i = 0, f = 0; i < n + 1; i++) {
            if(i < n && s.charAt(i) == 'D')
                continue;
            for(int k = i + 1; f <= i; f++)
                res[f] = k--;
        }
        return res;
    }

Log in to reply
 

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