LC 1614. Maximum Nesting Depth of the Parentheses

Nilanjan Deb · October 11, 2020

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


Dicussion Forum