Given a string containing just the characters (), [], {}, determine if the input string is valid.
The brackets must close in the correct order.
思路
在考虑这样的题目的时候,边界条件一定要判断清楚。首先,不是说任意一对括号相配对就可以了,还需要考虑括号的种类;其次,括号的配对不能错位嵌套。
本题利用堆栈可以很容易解决。
|
|
Given a string containing just the characters (), [], {}, determine if the input string is valid.
The brackets must close in the correct order.
在考虑这样的题目的时候,边界条件一定要判断清楚。首先,不是说任意一对括号相配对就可以了,还需要考虑括号的种类;其次,括号的配对不能错位嵌套。
本题利用堆栈可以很容易解决。
|
|
近期评论