Skip to content
Snippets Groups Projects
Select Git revision
  • c88ceb6fe3c249d72b82a5746d7409c77e624532
  • master default
2 results

RegisterActivity.java

Blame
  • cse16218_ex2_10.py 509 B
    def depth(s, n): 
        current_max = 0
        final_max = 0
        
        for i in range(n): 
            if s[i] == '(': 
                current_max += 1
      
                if current_max > final_max: 
                    final_max = current_max 
            elif s[i] == ')': 
                if current_max > 0: 
                    current_max -= 1
                else: #unbalanced
                    return -1
                    
        if current_max != 0: #unbalanced
            return -1
      
        return final_max
      
    s = input()
    print (depth(s, len(s)))