Compare commits

..

2 Commits

Author SHA1 Message Date
carry
755923c349 cpp模版 2025-02-20 17:32:49 +08:00
carry
f6adc921e5 括号匹配 2025-02-14 13:41:13 +08:00
2 changed files with 62 additions and 0 deletions

12
template.cpp Normal file
View File

@ -0,0 +1,12 @@
#include<iostream>
#include<vector>
class Solution {
public:
};
int main(){
return 0;
}

50
validParentheses.cpp Normal file
View File

@ -0,0 +1,50 @@
#include<iostream>
#include<stack>
using namespace std;
class Solution {
public:
bool isValid(string s) {
stack<char> str;
for(auto i: s){
switch(i){
case '(':
case '{':
case '[':
str.push(i);
break;
default:
if(str.size() == 0){
return false;
}
switch(i){
case ')':
if (str.top() != '('){return false;}
else{str.pop();}
break;
case ']':
if (str.top() != '['){return false;}
else{str.pop();}
break;
case '}':
if (str.top() != '{'){return false;}
else{str.pop();}
break;
}
}
}
if(str.size() == 0){
return true;
}
else{
return false;
}
}
};
int main(){
cout << Solution().isValid("([])");
return 0;
}