Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdb79894

Browse files
authored
Create _2116.cpp
Solution for the Leetcode problem2116. Check if a Parentheses String Can Be Valid
1 parente3f477d commitdb79894

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

‎cpp/_2116.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
classSolution {
2+
public:
3+
boolcanBeValid(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+
for(int i =0;i<n;i++)
13+
{
14+
if(s[i]=='(')open.push(i);
15+
elseif(s[i]=='*') star.push(i);
16+
elseif(s[i]==')')
17+
{
18+
if(!open.empty())open.pop();
19+
elseif(!star.empty()) star.pop();
20+
elsereturnfalse;
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+
returnfalse;
30+
return (open.empty());
31+
}
32+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp