个人注释
#define MAX(a, b) ((a) > (b) ? (a) : (b))
int maxDepth(char* s) { //没有用栈的存储结构,但用了栈的思想
int ans = 0, size = 0; //size为栈的高度
int n = strlen(s);
for (int i = 0; i < n; ++i) {
if (s[i] == '(') {
++size;
ans = MAX(ans, size); //ans记录出现过的最大 栈高度
}
else if (s[i] == ')') {
--size;
}
}
return ans;
}
作者:力扣官方题解
链接:https ://leetcode.cn/problems/maximum-nesting-depth-of-the-parentheses/solutions/1194617/gua-hao-de-zui-da-qian-tao-shen-du-by-le-av5b/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。