Dashboard Temp Share Shortlinks Frames API

HTMLify

expression-contains-redundant-bracket-or-not.py
Views: 2 | Author: prakhardoneria
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
class Solution():
    def checkRedundancy(self, s):
        st = []
        for char in s:
            if char == ')':
                top = st.pop()
                is_redundant = True
                while top != '(':
                    if top in '+-*/':
                        is_redundant = False
                    top = st.pop()
                if is_redundant:
                    return True
            else:
                st.append(char)
        return False