020.Valid Parentheses Posted on 2017-09-13 | In LeetCode Solution 1: acceptedThis is an easy one.1234567891011121314151617181920212223242526272829303132public class Solution { public boolean isValid(String s) { Stack cache = new Stack(); for (int i = 0; i < s.length(); i++) { char current = s.charAt(i); if (current == '(' || current == '[' || current == '{') cache.push(current + ""); if (current == ')') if (!cache.isEmpty() && cache.peek().equals("(")) cache.pop(); else return false; if (current == ']') if (!cache.isEmpty() && cache.peek().equals("[")) cache.pop(); else return false; if (current == '}') if (!cache.isEmpty() && cache.peek().equals("{")) cache.pop(); else return false; } return cache.isEmpty(); }}