This is my CPP solution.
class Solution {
public:
int maxDepth(string s) {
int len = 0, mx = 0;
int n = s.size();
for(int i=0;i<n;i++) {
if(s[i] == '(') {
len++;
}else if(s[i] == ')') {
mx = max(len, mx);
len--;
}
}
return mx;
}
};