class Solution {
if valid parenthesis "()=true" ,"()[]{}=true","(]=false","([)]=false","{[]}=true
public boolean isValid(String s) {
Stack<Character> p=new Stack<>();
for(char c:s.toCharArray()){
if(c== '('){
p.push(')');
}
else if(c== '{'){
p.push('}');
}
else if(c== '['){
p.push(']');
}
else if(p.isEmpty()||p.pop()!=c){
return false;
}
}
return p.isEmpty();
}
}
Aucun commentaire:
Enregistrer un commentaire