<2017年6月>
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

统计

  • 随笔 - 57
  • 文章 - 7
  • 评论 - 0
  • 引用 - 0

常用链接

留言簿

随笔分类

随笔档案

文章分类

文章档案

Blog

Coder 必备技巧

Compiler for Wurq

搜索

  •  

最新评论

阅读排行榜

评论排行榜

【LeeCode 2017/06/27】20. Valid Parentheses
 1 class Solution {
 2 public:
 3     bool isValid(string s) {
 4         stack<char>q;
 5         for (int i = 0; i < s.length(); i++)
 6         {
 7             char ch = s[i];
 8             if (!q.empty())
 9             {
10                 if (ch == ')' &&q.top() == '(' ||
11                     ch == ']' &&q.top() == '[' ||
12                     ch == '}' &&q.top() == '{')
13                     q.pop();
14                 else
15                     q.push(ch);
16             }
17             else
18                 q.push(ch);
19         }
20         int ret = false;
21         if (q.empty())
22             ret = true;
23 
24         return ret;
25     }
26 };
27 

posted on 2017-06-27 09:49 Wurq 阅读(102) 评论(0)  编辑 收藏 引用 所属分类: 【LeeCode 每日N题】


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理