Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions 0020VALIDPARENTHESIS.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
class Solution {
public boolean isValid(String s) {
Stack<Character> st = new Stack<>();

for(int i= 0 ; i<s.length();i++){
char ch= s.charAt(i);

if (ch=='('|| ch=='[' || ch=='{'){
st.push(ch);

}
else{
if(st.isEmpty()){
return false;

}
else if(ch==']' && st.peek()!='['){
return false;

}

else if(ch=='}' && st.peek()!='{'){
return false;

}
else if(ch==')' && st.peek()!='('){
return false;

}



st.pop();


}

}
if(st.isEmpty()){
return true;

}
else {


return false;

}

}
}