首页 > 其他 > 详细

LeetCode – Refresh – Valid Parentheses

时间:2015-03-25 08:55:38      阅读:141      评论:0      收藏:0      [点我收藏+]
 1 class Solution {
 2 public:
 3     bool isValid(string s) {
 4         int len = s.size();
 5         if (len%2 == 1) return false;
 6         stack<char> list;
 7         for (int i = 0; i < len; i++) {
 8             if (s[i] == ( || s[i] == [ || s[i] == {) {
 9                 list.push(s[i]);
10             } else if (!list.empty() && (s[i] == ) && list.top() == ( ||
11                 s[i] == ] && list.top() == [ ||
12                 s[i] == } && list.top() == {)) {
13                     list.pop();
14             }
15         }
16         return list.empty();
17     }
18 };

 

LeetCode – Refresh – Valid Parentheses

原文:http://www.cnblogs.com/shuashuashua/p/4364627.html

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