# Sprint 3 Module Project 2 ## queueOnStacks ``` def queueOnStacks(requests): left = Stack() right = Stack() def insert(x): left.push(x) def remove(): while not left.isEmpty(): right.push(left.pop()) res = right.pop() while not right.isEmpty(): left.push(right.pop()) return res ans = [] for request in requests: req = request.split(" ") if req[0] == 'push': insert(int(req[1])) else: ans.append(remove()) return ans ``` ## validBracketSequence ``` from collections import deque mapping = {')': '(', '}': '{', ']': '['} def validBracketSequence(sequence): stack = deque() for char in sequence: if char == '(' or char == '{' or char == '[': stack.append(char) else: if len(stack) == 0 or mapping[char] != stack[-1]: return False else: stack.pop() return len(stack) == 0 ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up