Compare commits
No commits in common. "755923c349681f7504b9054c8077b5e271797aa5" and "8dc2f5e9a5bcd239005cbac212ae4d019ce550f1" have entirely different histories.
755923c349
...
8dc2f5e9a5
12
template.cpp
12
template.cpp
@ -1,12 +0,0 @@
|
|||||||
#include<iostream>
|
|
||||||
#include<vector>
|
|
||||||
|
|
||||||
class Solution {
|
|
||||||
public:
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
#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;
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user