/*
* @lc app=leetcode.cn id=942 lang=typescript
*
* [942] 增减字符串匹配
*/
// @lc code=start
function diStringMatch(s: string): number[] {}
// @lc code=end
function diStringMatch(s: string): number[] {
let n = s.length,
res: number[] = [],
min = 0,
max = n
for (let i = 0; i <= n; i++) {
res.push(s[i] === 'I' ? min++ : max--)
}
return res
}
test.each([
{ input: { s: 'IDID' }, output: [0, 4, 1, 3, 2] },
{ input: { s: 'III' }, output: [0, 1, 2, 3] },
{ input: { s: 'DDI' }, output: [3, 2, 0, 1] },
])('input: s = $input.s', ({ input: { s }, output }) => {
expect(diStringMatch(s)).toEqual(output)
})