942. DI String Match
Last updated
Last updated
class Solution {
public:
vector<int> diStringMatch(string S) {
vector<int> res;
int n = S.length(), f = 0, b = n;
for (int i = 0; i <= n; i++) {
if (S[i] == 'I') {
res.push_back(f);
f++;
} else {
res.push_back(b);
b--;
}
}
return res;
}
};