Skip to content

Commit

Permalink
2024-03-10 보석 쇼핑
Browse files Browse the repository at this point in the history
  • Loading branch information
fnzksxl committed Mar 10, 2024
1 parent 6bf65ee commit 5f62951
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions fnzksxl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
| 8차시 | 2024-02-20 | DP | [동전1](https://www.acmicpc.net/problem/2293) | [#32](https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/32) |
| 9차시 | 2024-02-23 | 그래프 | [순위](https://school.programmers.co.kr/learn/courses/30/lessons/49191) | [#37](https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/37) |
| 10차시 | 2024-03-07 | 구현 | [나무 재테크](https://www.acmicpc.net/problem/16235) | [#52](https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/52) |
| 11차시 | 2024-03-10 | 투포인터 | [보석 쇼핑](https://school.programmers.co.kr/learn/courses/30/lessons/67258) | [#56](https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/56) |
---
26 changes: 26 additions & 0 deletions fnzksxl/투포인터/보석 쇼핑.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
def solution(gems):
answer = []
head, tail = 0, 0
gem_length = len(set(gems))
gems_dict = {}
gem_min = len(gems) + 1

while head <= tail < len(gems):
gems_dict[gems[tail]] = gems_dict.get(gems[tail], 0) + 1
tail+=1

if len(gems_dict) == gem_length:
while head < tail:
if gems_dict[gems[head]] > 1:
gems_dict[gems[head]] -= 1
head += 1

elif gem_min > tail - head:
gem_min = tail - head
answer = [head+1, tail]
break

else:
break

return answer

0 comments on commit 5f62951

Please sign in to comment.