码迷,mamicode.com
首页 > 其他好文 > 详细

[LeetCode] Valid Parenthesis String 验证括号字符串

时间:2017-10-01 13:13:12      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:type   code   nbsp   note   etc   output   rac   character   har   

 

Given a string containing only three types of characters: ‘(‘, ‘)‘ and ‘*‘, write a function to check whether this string is valid. We define the validity of a string by these rules:

  1. Any left parenthesis ‘(‘ must have a corresponding right parenthesis ‘)‘.
  2. Any right parenthesis ‘)‘ must have a corresponding left parenthesis ‘(‘.
  3. Left parenthesis ‘(‘ must go before the corresponding right parenthesis ‘)‘.
  4. ‘*‘ could be treated as a single right parenthesis ‘)‘ or a single left parenthesis ‘(‘ or an empty string.
  5. An empty string is also valid.

 

Example 1:

Input: "()"
Output: True

 

Example 2:

Input: "(*)"
Output: True

 

Example 3:

Input: "(*))"
Output: True

 

Note:

  1. The string size will be in the range [1, 100].

 

s

 

[LeetCode] Valid Parenthesis String 验证括号字符串

标签:type   code   nbsp   note   etc   output   rac   character   har   

原文地址:http://www.cnblogs.com/grandyang/p/7617017.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!