力扣20 有效的括号

bool isValid(char * s){
       char a[3500];
    int current = -1;
    for(int i = 0;i < strlen(s);i++){

        if(s[i] == '(' || s[i] == '[' || s[i] == '{'){
            current++;
            a[current] = s[i];
        }

        else{
            if(current < 0) return false;

            if(s[i] == ')'){
                if(a[current] == '(')
                    current--;
                else
                    return false;
            }

            if(s[i] == ']'){
                if(a[current] == '[')
                    current--;
                else
                    return false;
            }

            if(s[i] == '}'){
                if(a[current] == '{')
                    current--;
                else
                    return false;
            }

        }
    }
    if(current < 0)
        return true;
    else
        return false;
}

 

posted @ 2020-06-21 08:36  军临天下jyj  阅读(160)  评论(0编辑  收藏  举报