leetcode 020-Valid Parentheses

problem:

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

example:

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

Difficulty:Easy

hint:

  • 使用一个栈存储左括号,碰到输入的字符为右括号时则出栈,并比较两个括号是否匹配。
  • 所有字符比较完成后,栈应为空,表示所有括号都相对应。

code:

#include 
#include
#include
//typedef int bool;
//#define true 1
//#define false 0
typedef enum {true=1, false=0} bool;
bool isValid(char* s){
    char* t = (char*)malloc(strlen(s)*sizeof(char));
    int i,j = 0;
    for(i = 0;i

你可能感兴趣的:(leetcode 020-Valid Parentheses)