Disclaimer: If in case violates the requirements, please let me know
Was it a necessary constraint to create a stack from scratch? List in python have underlying capability that works like Stack having same time complexity of pop(), append() as O(1),
Also a HashMap or dictionary in python to map key: values as{open:close}. Which also has O(1) time complexity for accessing an element. e.g.
mapping={'{':'}','[':']','(':')'}
Code redundancy can be reduced, long conditional statements makes code less readable. e.g.
if ((topmost_element == '[') and (x != ']')) or ((topmost_element == '(') and (x != ')')) or ((topmost_element == '{') and (x != '}')):
Thanks.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Disclaimer: If in case violates the requirements, please let me know
pop()
,append()
asO(1)
,{open:close}
. Which also hasO(1)
time complexity for accessing an element. e.g.if ((topmost_element == '[') and (x != ']')) or ((topmost_element == '(') and (x != ')')) or ((topmost_element == '{') and (x != '}')):
Thanks.