diff --git a/fnzksxl/README.md b/fnzksxl/README.md index a1ad866..318734c 100644 --- a/fnzksxl/README.md +++ b/fnzksxl/README.md @@ -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) | --- diff --git "a/fnzksxl/\355\210\254\355\217\254\354\235\270\355\204\260/\353\263\264\354\204\235 \354\207\274\355\225\221.py" "b/fnzksxl/\355\210\254\355\217\254\354\235\270\355\204\260/\353\263\264\354\204\235 \354\207\274\355\225\221.py" new file mode 100644 index 0000000..7e4729c --- /dev/null +++ "b/fnzksxl/\355\210\254\355\217\254\354\235\270\355\204\260/\353\263\264\354\204\235 \354\207\274\355\225\221.py" @@ -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 \ No newline at end of file