luoheng
10/7/2019 - 9:56 AM

diStringMatch

func diStringMatch(S string) []int {
    res := make([]int, len(S)+1)
    min, max := 0, len(S)
    for i := 0; i < len(S); i++ {
        if S[i] == 'D' {
            res[i] = max
            max--
        } else if S[i] == 'I' {
            res[i] = min
            min++
        }
    }
    res[len(S)] = min
    return res
}