leetcode 20 简单括号匹配

栈的运用

 1 class Solution {
 2 public:
 3     bool isValid(string s) {
 4         stack<char>The_Stack;
 5      int i=0;
 6      The_Stack.push('#');
 7      while(i<s.size()) {
 8          if((s[i]==')'&&The_Stack.top()=='(')||(s[i]==']'&&The_Stack.top()=='[')||(s[i]=='}'&&The_Stack.top()=='{')) {
 9              i++;
10              The_Stack.pop();
11          }
12          else  {
13          The_Stack.push(s[i]);
14          i++;
15          }
16      }
17      if(The_Stack.top()=='#')
18      return true;
19      return false;
20     }
21 };
原文地址:https://www.cnblogs.com/thefirstfeeling/p/5916359.html