Skip to content

Commit

Permalink
Merge pull request #38 from Manishak798/Manishak798-patch-34
Browse files Browse the repository at this point in the history
Create validParentheses.cpp
  • Loading branch information
Manishak798 authored Nov 19, 2024
2 parents 30684de + d612077 commit b6fb79c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Arrays/validParentheses.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Solution {
public:
bool isValid(string s) {
if(s.size() == 1){
return false;
}
stack <char> st;
for(int i=0; i<s.size(); i++){
if(s[i] == '(' || s[i] == '[' || s[i] == '{'){
st.push(s[i]);
}else{
if(st.empty()){
return false;
}
char ch = st.top();
st.pop();
if(s[i] == ')' && ch == '(' || s[i] == ']' && ch == '[' || s[i] == '}' && ch == '{'){
}else{
return false;
}
}
}
return st.empty();
}
};

0 comments on commit b6fb79c

Please sign in to comment.