Skip to content

Commit 7b83827

Browse files
authoredApr 10, 2017
Update validParentheses.java
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
1 parent 9ab343f commit 7b83827

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed
 

‎Company/Airbnb/validParentheses.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ public boolean isValid(String s) {
2222

2323
}
2424

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

2727
stack.pop();
2828

2929
}
3030

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

3333
stack.pop();
3434

3535
}
3636

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

3939
stack.pop();
4040

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

5353
}
5454

55-
}
55+
}

0 commit comments

Comments
 (0)
Please sign in to comment.