1. 232 : implement Queue using Stacks
class MyQueue(object):
def __init__(self):
self.data = []
self.size = 0
"""
Initialize your data structure here.
"""
def push(self, x):
self.data.append(x)
self.size += 1
#print self.data
"""
Push element x to the back of queue.
:type x: int
:rtype: None
"""
def pop(self):
if(self.size > 0):
self.size -= 1
pop_data = self.data[0]
self.data.remove(pop_data)
return pop_data
return 0
"""
Removes the element from in front of queue and returns that element.
:rtype: int
"""
def peek(self):
if(self.size > 0):
#print self.data[0]
return self.data[0]
else:
return 0
"""
Get the front element.
:rtype: int
"""
def empty(self):
if self.size == 0:
return 1
else:
return 0
"""
Returns whether the queue is empty.
:rtype: bool
"""
# 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()
'IT Technology' 카테고리의 다른 글
[LeetCode 290 word pattern] python - str.split 사용하기 (0) | 2019.04.02 |
---|---|
USB 5 Port 충전기 이지넷유비쿼터스 NEXT 05AC 사용기 (0) | 2015.08.31 |
스마트폰 무선 충전의 장단점 및 잘 사용하는 법 (0) | 2015.03.26 |
[Enagdget] 포드와 인텔은 자동차에서 얼굴과 제스쳐를 인식하길 원한다. (0) | 2015.03.24 |
[Engadget] 트위터에서 foursquare의 위치를 사용할 수 있게 변경 되었습니다. (0) | 2015.03.24 |