leetcode - 20.Valid Parentheses
2017-03-02 19:50
357 查看
Valid Parentheses
Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.The brackets must close in the correct order, “()” and “()[]{}” are all valid but “(]” and “([)]” are not.
Solution:
public boolean isValid(String s) { LinkedList<Character> stack = new LinkedList<Character>(); for (char c : s.toCharArray()) { if (c == '(') stack.push(')'); else if (c == '{') stack.push('}'); else if (c == '[') stack.push(']'); else if (stack.isEmpty() || stack.pop() != c) return false; } return stack.isEmpty(); }
相关文章推荐
- Leetcode-20. Valid Parentheses
- LeetCode 20. Valid Parentheses(合法括号序列)
- Leetcode 20. Valid Parentheses
- leetcode[20]Valid Parentheses
- LeetCode 20. Valid Parentheses
- leetCode 20 Valid Parentheses
- LeetCode 20. Valid Parentheses
- LeetCode 20. Valid Parentheses--验证括号是否有效
- [LeetCode] 20. Valid Parentheses
- [leetcode] 20. Valid Parentheses
- LeetCode | 20. Valid Parentheses
- [leetcode 20] Valid Parentheses
- LeetCode 20. Valid Parentheses
- 20. Valid Parentheses Leetcode Python
- [Leetcode]20. Valid Parentheses
- Leetcode 20 Valid Parentheses
- Leetcode 20. Valid Parentheses
- leetCode 20.Valid Parentheses (有效的括号) 解题思路和方法
- leetcode 20. Valid Parentheses——python(easy)——使用了堆栈
- leetcode 20 Valid Parentheses 括号匹配