leetcode-1111

这道题主要是读题意,但是问题是题意翻译的很差劲,而且这道题并没有唯一期望。

至于读懂题意后的代码,就很简单了。

func maxDepthAfterSplit(seq string) []int {
	depth := 0
	var ans []int
	for _, c := range seq {
		if c == '(' {
			depth++
			ans = append(ans, depth % 2)
		} else {
			ans = append(ans, depth % 2)
			depth--
		}
	}
	return ans
}

  

end

猜你喜欢

转载自www.cnblogs.com/CherryTab/p/12616893.html