class Solution {
public boolean isValid(String s) {
int[] stack = new int[s.length()];
int index = 0;
for(int i = 0;i < s.length();i++){
char c = s.charAt(i);
if(index == 0 && (c == ')' || c == ']' || c == '}')){
return false;
}
if(c == '(' || c == '[' || c == '{'){
stack[index] = s.charAt(i);
index++;
}else if(c == ')' && stack[index-1] == '(' || c == ']' && stack[index-1] == '[' || c == '}' && stack[index-1] == '{'){
index--;
}else{
return false;
}
}
if(index == 0){
return true;
}else {
return false;
}
}
}
4/17/26Less than 1 minute