Advertisement
Iam_Sandeep

check redundant braces in valid math expression

Feb 15th, 2022
782
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. https://www.codingninjas.com/codestudio/problems/redundant-brackets_975473?leftPanelTab=1
  2. def findRedundantBrackets(s:str):
  3.     st=[]
  4.     if s=='':return False
  5.     sym='(+-/*' #no close brack
  6.     for i in s:
  7.         if i in sym :#any other symb than close br
  8.             st.append(i)
  9.         elif i==')':
  10.             if st[-1]=='(':
  11.                 return True
  12.             else:
  13.                 while st[-1]!='(':st.pop()
  14.             st.pop()
  15.         else:
  16.             continue #skipping variables
  17.     return False
  18.            
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement