题目链接:https://leetcode.com/problems/valid-parentheses/
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.
typedef struct StackRecord { //不考虑溢栈实现简单的堆栈 char ch[100]; int top; }*Stack; bool isEmpty(Stack stack) { if (stack->top >= 0) return false; return true; } Stack init() { Stack stack = (Stack)malloc(sizeof(struct StackRecord)); stack->top = -1; return stack; } void push(char ch, Stack stack) { stack->ch[++stack->top] = ch; } char top(Stack stack) { //返回栈顶元素,空栈时返回'