We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
defgetKey(c):if(c=='{'):return1if(c=='}'):return2if(c=='('):return3if(c==')'):return4if(c=='['):return5if(c==']'):return6defisBalanced(s):# Write your code herearrCharacter=list(s)stack=[]forxinarrCharacter:if(len(stack)==0orgetKey(x)!=1+getKey(stack[-1])):stack.append(x)else:stack.pop()print(stack)return"YES"iflen(stack)==0else"NO"
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Balanced Brackets
You are viewing a single comment's thread. Return to all comments →
Python