-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path2116.cpp
More file actions
28 lines (28 loc) · 684 Bytes
/
2116.cpp
File metadata and controls
28 lines (28 loc) · 684 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Solution {
public:
bool canBeValid(string s, string locked) {
int n = s.size();
if (n & 1) return false;
int lower = 0;
int upper = 0;
for (int i = 0; i < n; ++i) {
if (locked[i] == '1') {
if (s[i] == '(') {
upper++;
lower++;
}
else {
upper--;
lower--;
}
}
else {
upper++;
lower--;
}
if (lower < 0) lower += 2;
if (upper < 0) return false;
}
return lower == 0;
}
};