Advertisement

天梯赛 括号匹配

阅读量:

Description

Given a string P only consist of characters with (), [] and {}. Now BaoBao wants to know whether P can form a valid bracket string.

We define a pair that for each (, we can find a ) behind it. In the same way, [ and { also can find their ] and }. For example:

复制代码
    In string "()": ( and ) formed a pair;
    In string "[)(]": [ and ] formed a pair, but ( and ) are not;
    In string "{(})[{(}])", there exist 5 pairs.
    
    
      
      
      
    

一个有效的括号字符串是指字符串中括号配对的数量N能够满足N=∣P∣÷2的条件,其中符号∣P∣代表字符串P的总长度。例如,“(()())”、“({})”、“([)]”以及“{[(]})”均属于有效括号字符串,而“(()”、“)(”和“{{(})”

全部评论 (0)

还没有任何评论哟~