We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e3f477d commit db79894Copy full SHA for db79894
cpp/_2116.cpp
@@ -0,0 +1,32 @@
1
+class Solution {
2
+public:
3
+ bool canBeValid(string s, string locked) {
4
+ int n = s.size();
5
+ for(int i = 0;i<n;i++)
6
+ {
7
+ if(locked[i]=='0')
8
+ s[i] = '*';
9
+ }
10
+ cout<<s<<endl;
11
+ stack<int> open,star;
12
13
14
+ if(s[i]=='(') open.push(i);
15
+ else if(s[i]=='*') star.push(i);
16
+ else if(s[i]==')')
17
18
+ if(!open.empty()) open.pop();
19
+ else if(!star.empty()) star.pop();
20
+ else return false;
21
22
23
+ while(!open.empty() && !star.empty() && open.top() < star.top())
24
25
+ open.pop();
26
+ star.pop();
27
28
+ if(star.size()%2)
29
+ return false;
30
+ return (open.empty());
31
32
+};
0 commit comments