#include <stdio.h>
#include <string.h>
int longestValidParentheses(const char *s)
{
int left = 0;
int n = 0;
int i = 0;
if (NULL == s) {
return 0;
}
for (i = 0; s[i] != '\0'; i++) {
if (s[i] == '(') {
left++;
} else if (s[i] == ')' && left > 0) {
left--;
n++;
}
}
return n*2;
}
//start 提示:自動閱卷起始唯一標識,請勿刪除或增加。
int main()
{
//..
int len = 0;
len = longestValidParentheses("( () () )");
printf("() length is %d\n", len);
return 0;
}
//end //提示:自動閱卷結束唯一標識,請勿刪除或增加。