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)"))

12th Feb 2019, 6:22 AM
Shaik Abeedh
Shaik Abeedh - avatar
3 Réponses
+ 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
12th Feb 2019, 8:32 AM
Николай Шаповаленко
Николай Шаповаленко - avatar
+ 3
Please save it as a code so we can run it and see. Also, do you actually have a question here?
12th Feb 2019, 7:56 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 1
Thanks for your help
12th Feb 2019, 9:59 AM
Shaik Abeedh
Shaik Abeedh - avatar