-
71. Implement Queue using StacksProblem Solving 2023. 1. 14. 19:39728x90
Implement Queue using Stacks - LeetCode
Implement Queue using Stacks - Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, peek, pop, and empty). Implement the MyQueue class: * void push(int x) Pushes
leetcode.com
Queue class 안에 queue의 역할을 할 수 있도록 push, pop 등의 함수를 구현하는 문제
class MyQueue: def __init__(self): self.li = [] def push(self, x: int) -> None: self.li.append(x) def pop(self) -> int: return self.li.pop(0) def peek(self) -> int: return self.li[0] def empty(self) -> bool: if len(self.li) == 0: return True else: return False # Your MyQueue object will be instantiated and called as such: # obj = MyQueue() # obj.push(x) # param_2 = obj.pop() # param_3 = obj.peek() # param_4 = obj.empty()
input 형식이 이해가 안 가서 이게 맞나...? 하면서 짜놓고 일단 제출했는데 accept 됨
'Problem Solving' 카테고리의 다른 글
73. Fizz Buzz (0) 2023.01.14 72. Day of the Year (0) 2023.01.14 70. 카드2 (0) 2023.01.14 69. 큐 2 (0) 2023.01.14 68. 크레인 인형뽑기 게임 (1) 2023.01.09