DESCRIPTION:
Write a function that takes a string of parentheses, and determines if the order of the parentheses is valid. The function should return true if the string is valid, and false if it's invalid.
Examples
"()" => true
")(()))" => false
"(" => false
"(())((()())())" => true
Constraints
0 <= input.length <= 100
Along with opening (() and closing ()) parenthesis, input may contain any valid ASCII characters. Furthermore, the input string may be empty and/or not contain any parentheses at all. Do not treat other forms of brackets as parentheses (e.g. [], {}, <>).
def valid_parentheses(string):
newString=""
for i in string:
if ord(i) in (40,41):
newString+=i
while "()" in newString:
newString=newString.replace("()","")
return newString==""
'알고리즘 문제 > CodeWar' 카테고리의 다른 글
Bouncing Balls (0) | 2022.10.07 |
---|---|
Valid Braces (0) | 2022.10.06 |
RGB to Hex Conversion (0) | 2022.10.06 |
Human Readable Time (0) | 2022.10.05 |
Moving Zeros To The End (1) | 2022.10.05 |