#678
Valid Parenthesis String
medium· Greedyruns: 0Given a string s containing only three types of characters: '(', ')' and '*', return true if s is valid. Rules: any left parenthesis must have a matching right; any right must have a matching left; left must come before its corresponding right; '*' can be treated as a single right, a single left, or an empty string.
sign in to paste and practice your own solution
wpm 0acc 100%time 0:000 / 438
class Solution:
def checkValidString(self, s: str) -> bool:
low = high = 0
for c in s:
if c == "(":
low += 1
high += 1
elif c == ")":
low -= 1
high -= 1
else:
low -= 1
high += 1
if high < 0:
return False
low = max(low, 0)
return low == 0
click the box to focus · tab inserts 4 spaces · backspace to correct · esc to pause
desktop only
codedrill is a typing game and needs a real keyboard. open this on a laptop or desktop to practice.
you can still browse problems and sections from your phone.