Skip to content

Commit bb4b315

Browse files
committed
120125
1 parent 3191213 commit bb4b315

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# leetcode submit region begin(Prohibit modification and deletion)
2+
3+
4+
class Solution:
5+
def canBeValid(self, s: str, locked: str) -> bool:
6+
def good(s, locked, opener):
7+
opened = 0
8+
unlocked = 0
9+
for char, lock in zip(s, locked):
10+
if lock == "0":
11+
unlocked += 1
12+
elif char == opener:
13+
opened += 1
14+
elif opened > 0:
15+
opened -= 1
16+
elif unlocked > 0:
17+
unlocked -= 1
18+
else:
19+
return False
20+
return (opened - unlocked) % 2 == 0
21+
22+
return good(s, locked, "(") and good(s[::-1], locked[::-1], ")")
23+
24+
25+
# leetcode submit region end(Prohibit modification and deletion)
26+
27+
28+
class CheckIfAParenthesesStringCanBeValid(Solution):
29+
pass

0 commit comments

Comments
 (0)