Valid Parentheses 合法的括号匹配
来源:互联网 发布:淘宝代购延长收货 编辑:程序博客网 时间:2024/05/16 09:38
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.
题目大意:给定一个字符串只包含“(){}[]”,判断该字符串的括号是否匹配
思路:利用栈的思想,不匹配入栈,匹配出栈,最后查看栈顶
#include <string.h>bool isValid(char* s) { int len = strlen(s); char *p = malloc(len); int top = 0; //从下标1开始存储 if(!p) return false; memset(p, 0x0, len); while(*s) { //查看assic码,得知匹配情况的assic码差值 if(*s - p[top] == 1 || *s - p[top] == 2) { p[top] = 0; top--; } else { top++; p[top] = *s; } s++; } free(p); return (top ? false : true);}
0 0
- Valid Parentheses 合法的括号匹配
- Valid Parentheses 合法括号
- Valid Parentheses 合法的匹配 栈实现
- Valid Parentheses --括号匹配
- Valid Parentheses:括号匹配
- 多种括号的匹配 Valid Parentheses
- Longest Valid Parentheses 最长的合法括号序列
- 20. Valid Parentheses--合法的括号组合(使用stack)
- [LeetCode] 最长合法括号 longest valid parentheses
- 20.Valid Parentheses&合法括号序列判断
- 20.Valid Parentheses (括号匹配)
- LeetCode 32 Longest Valid Parentheses 最大合法括号匹配长度计算 动态规划算法有待学习
- 合法的括号匹配
- 寻找最长的括号匹配 Longest Valid Parentheses
- LeetCode | Longest Valid Parentheses(最长有效的括号匹配)
- 20.Valid Parentheses 栈的应用:括号匹配
- 【栈操作&括号匹配】Valid Parentheses
- LeetCode | Valid Parentheses(括号匹配)
- LoadRunner函数详解之web_url
- How to check the entitlements on my Application's Signature
- 自定义cell 通讯录
- HDFS实现其高可靠性的策略及机制
- java(08-13)
- Valid Parentheses 合法的括号匹配
- Java 基础 if和switch 练习记录
- iOS开发关于图片拉伸应用stretchableImageWithLeftCapWidth
- C小加 之 随机数(去重) C++ string之unique(),erase(),sort()使用小记
- Regionals 2014 Asia - Daejeon
- Android--在一个Button上显示不同类型的字体
- fatal error LNK1123: 转换到 COFF 期间失败
- Java 基础 for 和 while 的学习记录
- 【HDU4507】【吉哥系列故事——恨7不成妻】【变形数位dp】