Skip to content

Commit

Permalink
Update validParentheses.java
Browse files Browse the repository at this point in the history
fix code logic error leading to incorrect solution:

top of stack should be an opening parenthesis if current character is a closing parenthesis for string to be valid
  • Loading branch information
doshprompt authored Apr 10, 2017
1 parent 9ab343f commit 7b83827
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Company/Airbnb/validParentheses.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ public boolean isValid(String s) {

}

else if(s.charAt(i) == ')' && !stack.isEmpty() && stack.peek() == ')') {
else if(s.charAt(i) == ')' && !stack.isEmpty() && stack.peek() == '(') {

stack.pop();

}

else if(s.charAt(i) == ']' && !stack.isEmpty() && stack.peek() == ']') {
else if(s.charAt(i) == ']' && !stack.isEmpty() && stack.peek() == '[') {

stack.pop();

}

else if(s.charAt(i) == '}' && !stack.isEmpty() && stack.peek() == '}') {
else if(s.charAt(i) == '}' && !stack.isEmpty() && stack.peek() == '{') {

stack.pop();

Expand All @@ -52,4 +52,4 @@ else if(s.charAt(i) == '}' && !stack.isEmpty() && stack.peek() == '}') {

}

}
}

0 comments on commit 7b83827

Please sign in to comment.