[HackerRank][Python3] Queues: A Tale of Two Stacks
2018. 7. 19. 23:18 |
프로그래밍/HackerRank
Problem :
https://www.hackerrank.com/challenges/ctci-queue-using-two-stacks/problem
My Solution :
#!/usr/bin/env python3 class Node(object): def __init__(self, data=None): self.data = data self.right = None class MyQueue(object): def __init__(self): self.head = Node() self.tail = self.head def peek(self): if self.head.right: return self.head.right.data def pop(self): if self.head.right: data = self.head.right.data self.head = self.head.right self.head.data = None return data def put(self, value): self.tail.right = Node(value) self.tail = self.tail.right queue = MyQueue() t = int(input()) for line in range(t): values = map(int, input().split()) values = list(values) if values[0] == 1: queue.put(values[1]) elif values[0] == 2: queue.pop() else: print(queue.peek())
'프로그래밍 > HackerRank' 카테고리의 다른 글
[HackerRank][Python3] Recursion: Fibonacci Numbers (0) | 2018.07.20 |
---|---|
[HackerRank][Python3] Tree: Huffman Decoding (0) | 2018.07.20 |
[HackerRank][Python3] Binary Search Tree : Lowest Common Ancestor (0) | 2018.07.20 |
[HackerRank][Python3] Balanced Brackets (0) | 2018.07.20 |
[HackerRank][Python3] Abbreviation (0) | 2018.07.18 |
[HackerRank][Python3] Max Array Sum (0) | 2018.07.18 |
[HackerRank][Python3] Making Candies (0) | 2018.07.18 |
[HackerRank][Python3] Minimum Time Required (0) | 2018.07.17 |
최근에 달린 댓글 최근에 달린 댓글