Description
Difficulty: Easy
Given a string containing just the characters‘(‘, ‘)’, ‘{‘, ‘}’, ‘[‘ and ‘]’, determine if the input string is valid.
The brackets must close in the correct order, “()” and “()[]{}” are all valid but “(]” and “([)]” are not.
题意:
输入一列括号组合,数出是否合法,即括号是否先打开后关闭并且以正确顺序关闭。
Solution
实际上就是实现一个 stack。
这里使用 dict 类型来判断左右括号是否对应。
|
|





近期评论