add: 220107-CN
This commit is contained in:
parent
835292dbb6
commit
5ba6b214c2
|
|
@ -0,0 +1,24 @@
|
||||||
|
#include <cstdio>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class Solution {
|
||||||
|
public:
|
||||||
|
static int maxDepth(const std::string& s) {
|
||||||
|
int ret = 0, current = 0;
|
||||||
|
for (const char* ptr = s.c_str(); *ptr; ++ptr)
|
||||||
|
switch (*ptr) {
|
||||||
|
case '(':
|
||||||
|
++current;
|
||||||
|
ret = current > ret ? current : ret;
|
||||||
|
break;
|
||||||
|
case ')':
|
||||||
|
--current;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::printf("%d\n", Solution::maxDepth("()()()(()())"));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue