【leetcode】括号的最大嵌套深度

 

int maxDepth(char * s){
    int cnt=0,max=0;
    for(int i=0; s[i]!='\0'; i++){
        if(s[i]=='('){
            cnt++;
            if(cnt>max)
                max=cnt;
        }          
        else if(s[i]==')')
            cnt--;
    }
    return max;
}

 

posted @ 2020-11-09 13:16  温暖了寂寞  阅读(413)  评论(0编辑  收藏  举报