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 | 29 | 30 | 31 |
Tags
- 젠센부등식
- ResNet
- pytorch
- SWEA #Python #알고리즘
- GAN
- DeepLearning
- AlexNet
- PRML
- NeuralTalk
- CycleGAN
- TorchHub
- MachineLearning
- bayesian
- ImageCaptioning
- 체비셰프부등식
- tensor
- Python
- bayes
- DeepLearing
- 마코프부등식
- Bayes'Rule
- 머신러닝
- Bayes'Theorem
Archives
- Today
- Total
euphoriaO-O
[Python][프로그래머스] 보석 쇼핑 본문
#2020카카오인턴십 문제
from collections import Counter
def solution(gems):
ans = [0,len(gems)]
n = len(set(gems))
i,j = 0,n # i,j커서를 움직임. j는 최소길이 n부터 시작
sets = Counter(gems[i:j]) # count sets
while (i >= 0 and j < len(gems)):
if len(sets) == n:
if j-i < ans[1]-ans[0]:
ans = [i,j]
else:
sets[gems[i]] -= 1
if sets[gems[i]] == 0:
del sets[gems[i]]
i += 1
else:
k = gems[j]
j += 1
if k not in sets:
sets[k] = 1
else:
sets[k] += 1
return [ans[0]+1, ans[1]]
'Programming > Algorithm' 카테고리의 다른 글
[Python][프로그래머스] 수식 최대화 (0) | 2020.07.11 |
---|---|
[Python][프로그래머스] 키패드 누르기 (0) | 2020.07.11 |
[Python] SWEA 1234 비밀번호 (0) | 2020.07.11 |
Comments