Skip to content

[2주차] 이유민 - 월 덱, 풍선 터뜨리기 #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 10, 2025
Merged

Conversation

Whatdoyumin
Copy link
Contributor

문제 풀이

  • Deque를 활용해서 push_front, push_back, pop_front, pop_back 같은 연산을 메서드로 분리해 처리했습니다.
  • 문자열 명령어는 startsWith로 구분했고, 숫자는 split으로 추출해 사용했습니다.
  • Deque는 ArrayDeque를 사용했고, 빈 덱일 경우 -1을 리턴하도록 예외 처리를 했습니다.
  • StringBuilder로 출력값을 모아 마지막에 한 번에 출력했습니다.
  1. 풍선 터뜨리기
  • 풍선 번호랑 이동값을 갖는 Balloon 클래스를 만들어서 Deque에 저장했고, 처음 풍선부터 하나씩 터뜨리면서 남은 풍선을 회전시켰습니다.
  • 양수면 오른쪽으로, 음수면 왼쪽으로 이동시켰고, 회전할 때는 pollFirst/addLast나 pollLast/addFirst를 이용했습니다.
  • 풍선이 터질 때마다 그 번호를 출력에 추가했고, 마지막엔 StringBuilder로 결과 출력했습니다.
  • 원형 구조를 직접 구현하지 않고 Deque 회전을 이용해 간단하게 처리했습니다.

@Whatdoyumin Whatdoyumin merged commit a4df278 into main Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant