LeetCode 20. Valid Parentheses
2017-02-21 11:06
483 查看
Given a string containing just the characters
The brackets must close in the correct order,
程序代码:
'(', ')', '{', '}', '[' and ']', determine if the input string is valid.
The brackets must close in the correct order,
"()"and
"()[]{}"are all valid but
"(]"and
"([)]"are not.
程序代码:
bool isValid(char* s) { char stack[10000]; char* p= s; int i= 0; while(*p!='\0') { if(*p=='('||*p=='['||*p=='{') { i++; stack[i]=*p; p++; } else if(*p==')'&&stack[i]=='(') { i--; p++; } else if(*p==']'&&stack[i]=='[') { i--; p++; } else if(*p=='}'&&stack[i]=='{') { i--; p++; } else return 0; } if(i>0) return 0; else return 1; }
相关文章推荐
- leetcode[20]:Valid Parentheses
- [Leetcode] 20. Valid Parentheses(Stack)
- 【Leetcode】20. Valid Parentheses
- leetcode20:Valid Parentheses
- 【LeetCode】20. Valid Parentheses
- Leetcode: 20. Valid Parentheses
- [LeetCode]20. Valid Parentheses
- LeetCode(20)Valid Parentheses
- leetcode之top100_01_twoSsum/top100_20_ValidParentheses
- [LeetCode-Algorithms-20] "Valid Parentheses" (2017.11.1-WEEK9)
- LeetCode 20.Valid Parentheses
- LeetCode20——Valid Parentheses
- LeetCode 20 Valid Parentheses
- LeetCode 20. Valid Parentheses
- leetcode-20. Valid Parentheses
- LeetCode: 20. Valid Parentheses
- LeetCode-20-Valid Parentheses(有效的括号)
- leetcode解题报告20. Valid Parentheses
- leetcode_20_Valid Parentheses (easy)
- LeetCode 20 -- Valid Parentheses