```
public int[] findPermutation(String s) {
int[] res = new int[s.length()+1];
Stack<Integer> stack = new Stack<Integer>();
int min = 0;
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c == 'D') stack.add(i);
else {
res[i] = ++min;
while (!stack.isEmpty()) res[stack.pop()] = ++min;
}
}
if (s.charAt(s.length()-1) == 'D') stack.add(s.length());
else res[res.length-1] = ++min;
while (!stack.isEmpty()) res[stack.pop()] = ++min;
return res;
}
```