zoukankan      html  css  js  c++  java
  • Leetcode#20 Valid Parentheses

    原题地址

    辅助栈

    代码:

     1 bool isValid(string s) {
     2         stack<char> st;
     3         
     4         for (auto c : s) {
     5             if (st.empty())
     6                 st.push(c);
     7             else if (c == ')') {
     8                 if (st.top() != '(')
     9                     return false;
    10                 st.pop();
    11             }
    12             else if (c == ']') {
    13                 if (st.top() != '[')
    14                     return false;
    15                 st.pop();
    16             }
    17             else if (c == '}') {
    18                 if (st.top() != '{')
    19                     return false;
    20                 st.pop();
    21             }
    22             else
    23                 st.push(c);
    24         }
    25         
    26         return st.empty();
    27 }
  • 相关阅读:
    第十次作业
    第八次作业
    作业七--1
    作业五
    作业六
    作业四
    作业一
    作业三
    作业2
    jsp第一次作业
  • 原文地址:https://www.cnblogs.com/boring09/p/4268518.html
Copyright © 2011-2022 走看看