1 2 3 4 5 6 7 8 9 10 11 12 13
| class Solution { public int[] diStringMatch(String s) { int n = s.length(), low = 0, high = n; int[] res = new int[n + 1];
for (int i = 0; i < n; i++) { res[i] = s.charAt(i) == 'I' ? low++ : high--; } res[n] = low;
return res; } }
|