括号匹配

Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.

The brackets must close in the correct order, “()” and “()[]{}” are all valid but “(]” and “([)]” are not.

Subscribe to see which companies asked this question.

class Solution {
public:bool isValid(string s) {char stack[5000];int top = 0;int len = s.size();for(int i = 0 ; i < len;i++ ){if(!top){stack[top++] = s[i];}else{switch(s[i]){case '(':case '[':case '{':stack[top++] = s[i];break;case ')':if(stack[top-1] == '('){top--;                            }else{return false;}break;case ']':if(stack[top-1] == '['){top--;}else{return false;}break;case '}':if(stack[top-1] == '{'){top--;}else{return false;}break;default:break;}}}if(top == 0){return true;}return false;}
};

leetcode-Valid Parenthese相关推荐

  1. LeetCode——Valid Parenthese

    Leetcode--Valid Parenthese #20 Given a string containing just the characters '(', ')', '{', '}', '[' ...

  2. 32 Longest Valid Parenthese

    32 Longest Valid Parenthese 题意 解法 代码 算法复杂度 注意 题目链接:32 Longest Valid Parenthese 题意 给出一个由字符'('或')'组成的字 ...

  3. LeetCode 20. Valid Parenthese

    题目: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the ...

  4. Leetcode 20.Valid Parenthese

    我的思路 很简单, 遇到 ().[].{} 这三对符号的左边的就入栈, 遇到右边的就直接将栈顶元素与其对应进行比较, 能组成一对符号就出栈, 否则就返回 false. 因为有 6 种情况就使用 swi ...

  5. LeetCode Valid Sudoku

    原题链接在这里:https://leetcode.com/problems/valid-sudoku/ 题目: Determine if a Sudoku is valid, according to ...

  6. leetcode Valid Palindrome

    题目连接 https://leetcode.com/problems/valid-palindrome/ Valid Palindrome Description Given a string, de ...

  7. leetcode—Valid Parentheses

    1.问题描述 Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if t ...

  8. LeetCode : Valid Parentheses

    问题: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the ...

  9. LeetCode - Valid Sudoku

    题目: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could ...

  10. LeetCode --- Valid Parentheses

    题目链接 Problem discription Given a string containing just the characters '(', ')', '{', '}', '[' and ' ...

最新文章

  1. K8s如何改变美团的云基础设施?
  2. 【fedora12】vlc-2.0.0编译
  3. 计算几何——圆卡精度cf1059D
  4. swift文档_Swift 正式进入 Windows 平台
  5. 华为AI开发平台ModelArts介绍和应用
  6. linux opera flash插件,Opera 浏览器找不到 flash 插件的解决方案
  7. RHEL7.0时间同步设置
  8. Ubuntu学习日记--Lesson8:make 21 | tee log.txt命令解析 (错误输出,重定向,管道符)
  9. TFN推出2.5G传输分析仪D240S 等待您来验证
  10. Excel插件POI-ET扩展(NiceXSSFWorkbook)说明
  11. 【IOS逆向】基本环境配置和脱壳初体验
  12. MySQL错误Got error -1 from storage engine
  13. Command CompileAssetCatalog emitted errors but did not return a nonzero exit code to indicate failur
  14. 工作第十六七周:生活这么繁琐,我们还要努力爱她
  15. valser网站(计算机视觉CV,CG学习交流社区)
  16. 英语单词:flight; fly
  17. c语言中怎么把大写字母转化为小写字母,c语言大小写字母怎么转化?
  18. Kotlin 协程探索
  19. 台式计算机各种接口的名称,值得收藏的电脑接口大全(图文版)
  20. 全球最具影响力的大数据企业排行榜

热门文章

  1. R语言兵器谱:数据科学家的十八般武艺
  2. 计算机专业要用多大显卡,10条解答:玩LOL电脑显存一般需要多大啊?
  3. 雷建平搜狐号创作者大会演讲:成为互联网产业的记录者
  4. html设置悬浮效果,html滑动仿悬浮球菜单效果的实现-电脑自学网
  5. 低成本网站渗透测试怎么找
  6. Failed to reconcile etcd plane: Failed to add etcd member [etcd-server05] to etcd cluster
  7. 做APP应该选用什么样的服务器?
  8. iOS 手写键盘与触摸手势冲突,导致崩溃闪退
  9. 语音增强:求语音增强评价:CSIG,CBAK和COVL的代码
  10. 独立网站和互联网服务