表达式 求值 栈应用 符合匹配 算术运算

https://leetcode-cn.com/problems/valid-parentheses/

func isValid(s string) bool {
	n := len(s)
	if n%2 != 0 {
		return false
	}
	f := func(a, b byte) bool {
		return (a == '{' && b == '}') || (a == '[' && b == ']') || (a == '(' && b == ')')
	}
	stack := []byte{}
	for i := 0; i < n; i++ {
		if len(stack) == 0 {
		} else {
			b := f(stack[len(stack)-1], s[i])
			if b {
				stack = stack[0 : len(stack)-1]
				continue
			}
		}
		stack = append(stack, s[i])
	}
	return len(stack) == 0
}

  

https://leetcode.cn/problems/evaluate-reverse-polish-notation/

https://leetcode.cn/problems/asteroid-collision/

https://leetcode.cn/problems/daily-temperatures/

 

posted @ 2019-01-27 23:32  papering  阅读(128)  评论(0编辑  收藏  举报