maximum-nesting-depth-of-the-parentheses.cpp (376B)
1 class Solution { 2 public: 3 int maxDepth(string s) { 4 int max = 0; 5 int current = 0; 6 for(int i = 0; i < s.size(); ++i) { 7 if(s[i] == '(') { 8 current += 1; 9 max = std::max(current,max); 10 } 11 if(s[i] == ')') { 12 current -= 1; 13 } 14 } 15 return max; 16 } 17 };