From a524deda64a80ed10f21d83343c986ecedfdf599 Mon Sep 17 00:00:00 2001 From: Yatharth Bhargava Date: Sun, 13 Feb 2022 20:28:16 +0530 Subject: [PATCH] Fied validParentheses #125 --- leetcode/string/ValidParentheses.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/leetcode/string/ValidParentheses.java b/leetcode/string/ValidParentheses.java index ee5a7bab..9a78a04b 100644 --- a/leetcode/string/ValidParentheses.java +++ b/leetcode/string/ValidParentheses.java @@ -13,11 +13,11 @@ public boolean isValid(String s) { for(int i = 0; i < s.length(); i++) { if(s.charAt(i) == '(' || s.charAt(i) == '[' || s.charAt(i) == '{') { stack.push(s.charAt(i)); - } 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(); } else { return false;