759. Valid Parenthesis String

0

Medium

Given a string s that consists of only three types of characters: '(', ')', and '*', determine if the string is valid. Return true if it is valid.
The following conditions define a valid string:
    Any left parenthesis '(' must have a corresponding right parenthesis ')'.
    Any right parenthesis ')' must have a corresponding left parenthesis '('.
    Left parenthesis '(' must appear before the corresponding right parenthesis ')'.
    The asterisk '*' can be treated as a single right parenthesis ')', a single left parenthesis '(', or an empty string "".

Input Format

A string containing special characters.

Output Format

A boolean value indicating whether the string is valid or not.

Example

Input

( *)

Output

true

Constraints

The length of the string s is less than 100
Loading...

View Submissions

Console