首页 > 其他 > 详细

leetcode 20 简单括号匹配

时间:2016-09-28 16:11:57      阅读:209      评论:0      收藏:0      [点我收藏+]

栈的运用

 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 };

 

leetcode 20 简单括号匹配

原文:http://www.cnblogs.com/thefirstfeeling/p/5916359.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!