add: 220107-CN

This commit is contained in:
Lam Haoyin 2022-01-07 18:13:51 +08:00
parent 835292dbb6
commit 5ba6b214c2
No known key found for this signature in database
GPG Key ID: 8C089CB1A2B7544F
1 changed files with 24 additions and 0 deletions

24
2201/220107-CN.cpp Normal file
View File

@ -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;
}