Open Zheaoli opened 2 years ago
func diStringMatch(s string) []int {
lo, hi, ans := 0, len(s), make([]int, len(s) + 1)
for i, ch := range s {
if (ch == 'I') {
ans[i] = lo
lo++
} else {
ans[i] = hi
hi--
}
}
ans[len(s)] = lo
return ans
}
WeChat: Saraad
package main
/*
* @lc app=leetcode.cn id=942 lang=golang
*
* [942] 增减字符串匹配
*/
// @lc code=start
func diStringMatch(s string) []int {
res := make([]int, 0)
start := 0
end := len(s)
for _, c := range s {
if c == 'I' {
res = append(res, start)
start++
} else {
res = append(res, end)
end--
}
}
res = append(res, end)
return res
}
// func main() {
// fmt.Println(diStringMatch("IDID"))
// }
// @lc code=end
微信id: 而我撑伞 来自 vscode 插件
2022-05-09