Skip to content

Commit 4d404d0

Browse files
authored
Update valid-parenthesis-string.py
1 parent 586c3fb commit 4d404d0

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

Python/valid-parenthesis-string.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
# Time: O(n)
22
# Space: O(1)
33

4+
# Given a string containing only three types of characters: '(', ')' and '*',
5+
# write a function to check whether this string is valid. We define the validity of a string by these rules:
6+
#
7+
# Any left parenthesis '(' must have a corresponding right parenthesis ')'.
8+
# Any right parenthesis ')' must have a corresponding left parenthesis '('.
9+
# Left parenthesis '(' must go before the corresponding right parenthesis ')'.
10+
# '*' could be treated as a single right parenthesis ')' or a single left parenthesis '(' or an empty string.
11+
# An empty string is also valid.
12+
# Example 1:
13+
# Input: "()"
14+
# Output: True
15+
# Example 2:
16+
# Input: "(*)"
17+
# Output: True
18+
# Example 3:
19+
# Input: "(*))"
20+
# Output: True
21+
# Note:
22+
# The string size will be in the range [1, 100].
23+
424
class Solution(object):
525
def checkValidString(self, s):
626
"""

0 commit comments

Comments
 (0)