Skip to content

Commit 875b618

Browse files
committed
Add solution for problem 2116: Check if a Parantheses String Can Be Valid and update README
1 parent 09b5359 commit 875b618

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution:
2+
def canBeValid(self, s: str, locked: str) -> bool:
3+
if len(s) % 2 == 1:
4+
return False
5+
6+
def check(s: str, locked: str, isForward: bool) -> bool:
7+
changeable = 0
8+
l = 0
9+
r = 0
10+
11+
for c, lock in zip(s, locked):
12+
if lock == '0':
13+
changeable += 1
14+
elif c == '(':
15+
l += 1
16+
else: # c == ')'
17+
r += 1
18+
if isForward and changeable + l - r < 0:
19+
return False
20+
if not isForward and changeable + r - l < 0:
21+
return False
22+
23+
return True
24+
25+
return check(s, locked, True) and check(s[::-1], locked[::-1], False)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ You can explore the solutions in the table below. Each row includes:
200200
| 2050 | Parallel Courses III | [![Medium](https://img.shields.io/badge/Medium-12100E?style=for-the-badge&logo=medium&logoColor=white)](https://medium.com/@_monitsharma/daily-leetcode-problems-2050-parallel-courses-iii-87d84ef83437) |
201201
| 2090 | K Radius Subarray Averages | [![Medium](https://img.shields.io/badge/Medium-12100E?style=for-the-badge&logo=medium&logoColor=white)](https://medium.com/@_monitsharma/daily-leetcode-problems-problem-2090-k-radius-subarray-averages-756dd59ce83) |
202202
| 2101 | Detonate the Maximum Bombs | [![Medium](https://img.shields.io/badge/Medium-12100E?style=for-the-badge&logo=medium&logoColor=white)](https://medium.com/@_monitsharma/daily-leetcode-problems-problem-2101-detonate-the-maximum-bombs-e1cc142d238d) |
203+
| 2116 | Check if a Parantheses String Can Be a Valid | [![Medium](https://img.shields.io/badge/Medium-12100E?style=for-the-badge&logo=medium&logoColor=white)](https://medium.com/@_monitsharma/daily-leetcode-problems-problem-2101-detonate-the-maximum-bombs-e1cc142d238d) |
203204
| 2130 | Maximum Twin sum of a Linked List | [![Medium](https://img.shields.io/badge/Medium-12100E?style=for-the-badge&logo=medium&logoColor=white)](https://medium.com/@_monitsharma/daily-leetcode-problems-problem-2130-maximum-twin-sum-of-a-linked-list-d7d4fd9fccde) |
204205
| 2140 | Solving Questions with Brainpower | [![Medium](https://img.shields.io/badge/Medium-12100E?style=for-the-badge&logo=medium&logoColor=white)](https://medium.com/@_monitsharma/daily-leetcode-problems-problem-2140-solving-questions-with-brainpower-4dfa9a0418a4) |
205206
| 2141 | Maximum Running time for N Computers | [![Medium](https://img.shields.io/badge/Medium-12100E?style=for-the-badge&logo=medium&logoColor=white)](https://medium.com/@_monitsharma/daily-leetcode-problems-problem-2141-maximum-running-time-of-n-computers-b7f8a94989be) |

0 commit comments

Comments
 (0)