Valid Parenthesis String

Medium

Description

Given a string s containing only '(', ')' and '*', return true if s is valid. '*' can be treated as '(', ')' or an empty string.

Examples

Input:s = "()"
Output:true
Explanation:

Simple valid parentheses.

Input:s = "(*)"
Output:true
Explanation:

* can be treated as empty.

Input:s = "(*))"
Output:true
Explanation:

Given s = "(*))", the condition holds: s is valid.

Constraints

  • 1 ≤ s.length ≤ 100
  • s consists of '(', ')' and '*'.

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!