mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 00:25:22 +08:00
18 lines
311 B
Go
18 lines
311 B
Go
package leetcode
|
|
|
|
func diStringMatch(S string) []int {
|
|
result, maxNum, minNum, index := make([]int, len(S)+1), len(S), 0, 0
|
|
for _, ch := range S {
|
|
if ch == 'I' {
|
|
result[index] = minNum
|
|
minNum++
|
|
} else {
|
|
result[index] = maxNum
|
|
maxNum--
|
|
}
|
|
index++
|
|
}
|
|
result[index] = minNum
|
|
return result
|
|
}
|