Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 디자인 패턴
- 빈 조회 2개 이상
- 전략패턴 #StrategyPattern #디자인패턴
- 디자인패턴
- @FeignClient
- jwt
- 취업리부트코스
- Spring multimodule
- 단기개발자코스
- KPT회고
- TiL
- 프로그래머스 이중우선순위큐
- infcon 2024
- 빈 충돌
- 인프콘 2024
- JavaScript
- DesignPattern
- spring batch 5.0
- jwttoken
- 1주일회고
- 구글 OAuth login
- 프로그래머스
- 파이썬
- 99클럽
- Python
- 커스텀 헤더
- 개발자 취업
- 항해99
- 개발자부트캠프추천
- 코딩테스트 준비
Archives
- Today
- Total
m1ndy5's coding blog
LeetCode 232. Implement Queue using Stacks with Python 본문
알고리즘 with python/알고리즘 스터디
LeetCode 232. Implement Queue using Stacks with Python
정민됴 2024. 1. 4. 10:17https://leetcode.com/problems/implement-queue-using-stacks/
class MyQueue:
def __init__(self):
self.stack = []
self.pointer = 0
def push(self, x: int) -> None:
self.stack.append(x)
def pop(self) -> int:
tmp = self.stack[self.pointer]
self.pointer += 1
return tmp
def peek(self) -> int:
return self.stack[self.pointer]
def empty(self) -> bool:
return self.pointer == len(self.stack)
Stack을 이용하여 Queue를 만들어보는 거였는데 흐음 이걸 스택을 사용해서 풀었다고 하기엔 좀 애매한 것 같다
Stack의 pop을 사용해서 풀어야했나 싶긴한데 그럼 너무 효율성이 떨어질 것 같아서 포인터를 사용해 풀었다.
이 코드의 단점은 포인터를 움직여서 Pop된 것처럼 보이게 했는데 사실은 데이터가 존재하고 있어서 메모리 사용면에서는 아~~주 별로인 코드인 것 같다.
노드로 구현하고 릴리즈 해주거나 진짜 한칸씩 계속 보내서 팝을 해주거나 하면 메모리적으로는 괜찮을 것같다!
'알고리즘 with python > 알고리즘 스터디' 카테고리의 다른 글
LeetCode 771. Jewels and Stones with Python (1) | 2024.01.04 |
---|---|
LeetCode 739. Daily Temperatures with Python (1) | 2024.01.04 |
LeetCode 225. Implement Stack using Queues (0) | 2024.01.04 |
LeetCode 561. Array Partition with Python (1) | 2024.01.03 |
LeetCode 15. 3Sum with Python (2) | 2024.01.03 |