0
I get time limit exceeded .butexpecting output is" true and no of matched parenthesis " and false if parenthesis are not mathed
def srr(s): f=[] for i in range(0,len(s)): if s[i]=="(": f.append(s[i]) for j in range(0,len(s)): if s[j]==")": f.append(s[j]) if len(f)%2==0: k=0 d=0 while k<len(f)/2: if f[k]==f[-(k+1)]: k=k+1 d=d+1 return (True,d) else: return False print(srr("g(f)(b)"))
3 Respuestas
+ 5
Pay attention to while loop. And return in your variant always will give False. Because f[k] = ( and f[-(k+1)] = ), but ( and ) can not be similar. i want say '(' != ')' -> true.
https://code.sololearn.com/cCAERTBo8G2C/?ref=app
+ 3
Please save it as a code so we can run it and see. Also, do you actually have a question here?
+ 1
Thanks for your help