leetcode#232 Implement Queue using Stacks

정은경·2022년 6월 21일
0

알고리즘

목록 보기
101/125

1. 문제

2. 나의 풀이

class MyQueue:

    def __init__(self):
        self.stack = []
        

    def push(self, x: int) -> None:
        self.stack.append(x)
        

    def pop(self) -> int:
        if(len(self.stack) > 0):
            return self.stack.pop(0)
        return
        

    def peek(self) -> int:
        if(len(self.stack) > 0):
            return self.stack[0]
        return
        
        
    def empty(self) -> bool:
        if(len(self.stack) > 0):
            return False
        return True
        


# 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()

Reference

profile
#의식의흐름 #순간순간 #생각의스냅샷

0개의 댓글