topic20

package
v0.0.0-...-b071cee Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2023 License: GPL-3.0 Imports: 0 Imported by: 0

README

有效的括号

1. 题目描述

给定一个只包括 '(',')','{','}','[',']' 的字符串 s ,判断字符串是否有效。

有效字符串需满足:

左括号必须用相同类型的右括号闭合。 左括号必须以正确的顺序闭合。

2. 示例

示例1

输入:s = "()"
输出:true

示例2

输入:s = "()[]{}"
输出:true

示例3

输入:s = "(]"
输出:false

示例4

输入:s = "([)]"
输出:false

示例5

输入:s = "{[]}"
输出:true

提示

  • $1 \le s.length \le 10^4$
  • s 仅由括号 '()[]{}' 组成

3. 解题

使用栈存储"(", "[", "{",遇到右括号就尝试从栈中取,若栈已空或取不到对应的左括号,则失败。

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL