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

    bool isValid(string s)
         {
             stack<char>st;        
             for (int i = 0; i < s.size();i++)
             {
                 switch (s[i])
                 {
                 case '(':
                 case '[':
                 case '{':st.push(s[i]); break;
                 case ')':if (st.empty() || st.top() != '(')return false; else st.pop(); break;
                 case '}': if (st.empty() || st.top() != '{') return false; else st.pop(); break;
                 case ']': if (st.empty() || st.top() != '[') return false; else st.pop(); break;
                 default:;
                 }              
             }
             return st.empty();        
         }
  • 相关阅读:
    paramiko
    Oracle 正则
    格式化输出
    pl/sql
    logging-----日志模块
    linux学习笔记01
    PHP-HTML-MYSQL表格添加删除
    费了好大劲做的比较好看的表单
    HTML框架
    两天笔记
  • 原文地址:https://www.cnblogs.com/hellowooorld/p/6907036.html
Copyright © 2011-2022 走看看