zoukankan      html  css  js  c++  java
  • [LeetCode20]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.

    代码:

    class Solution {
    public:
        bool isValid(string s) {
            stack<char> vec;
            for(char c : s)
            {
                switch(c)
                {
                case '(':
                case '[':
                case '{':
                    vec.push(c);
                    break;
                case ')':
                    if(vec.empty() || vec.top() != '(')
                        return false;
                    else
                        vec.pop();
                    break;
                case ']':
                    if(vec.empty() || vec.top() != '[')
                        return false;
                    else
                        vec.pop();
                    break;
                case '}':
                    if(vec.empty() || vec.top() != '{')
                        return false;
                    else
                        vec.pop();
                    break;
                }
            }
            return vec.empty();
        }
    };
  • 相关阅读:
    195
    194
    193
    192
    191
    190
    Oracle 11g使用rman从单实例迁移到RAC
    RESTful API 设计指南
    Oracle GoldenGate(OGG)- 超级详细
    【转】Oracle GoldenGate OGG管理员手册
  • 原文地址:https://www.cnblogs.com/zhangbaochong/p/5250284.html
Copyright © 2011-2022 走看看