[ 스택 / 큐 ] Programmers / 기능개발 / python

2024. 1. 31. 16:51·코딩테스트/programmers (python)

 

코딩테스트 연습 - 기능개발 | 프로그래머스 스쿨 (programmers.co.kr)

 

나의 풀이

from collections import deque
def solution(progresses, speeds):
    day = deque()
    result=[]
    state = zip(progresses, speeds)
    for p, s in state:
        if (100-p)%s!=0:
            day.append((100-p) // s + 1) 
        else:
            day.append((100-p) // s)  

    ...
    
    return result

100%가 될 때까지의 기간을 담은 리스트까지만 출력 / 배포 순서 출력을 위해 큐를 이용해 접근하려고 하였으나 어려움이 있었다.

 

모범 답안

def solution(progresses, speeds):
    answer = []
    time = 0
    count = 0
    while len(progresses)> 0:
        if (progresses[0] + time*speeds[0]) >= 100: 
            progresses.pop(0)
            speeds.pop(0)
            count += 1
        else:
            if count > 0:
                answer.append(count)
                count = 0
            time += 1
    answer.append(count)
    return answer

time 변수에 소요되는 일수를 누적시켜 저장하고 진도가 100이 넘으면 count를 1 증가 

'코딩테스트 > programmers (python)' 카테고리의 다른 글

Programmers / 2단계 / 점프와 순간 이동 / python  (0) 2024.01.31
[ 스택 / 큐 ] Programmers / 올바른 괄호 / python  (0) 2024.01.31
[ 스택 / 큐 ] Programmers / 같은 숫자는 싫어 / python  (0) 2024.01.31
Programmers / 2단계 / 멀리 뛰기 / python  (1) 2024.01.30
Programmers / 2단계 / 구명보트 / python  (1) 2024.01.30
'코딩테스트/programmers (python)' 카테고리의 다른 글
  • Programmers / 2단계 / 점프와 순간 이동 / python
  • [ 스택 / 큐 ] Programmers / 올바른 괄호 / python
  • [ 스택 / 큐 ] Programmers / 같은 숫자는 싫어 / python
  • Programmers / 2단계 / 멀리 뛰기 / python
seulll
seulll
개인 공부 / 정리 블로그입니다
  • seulll
    seulll
    seulll
  • 전체
    오늘
    어제
    • 분류 전체보기 (323) N
      • 코딩테스트 (223) N
        • programmers (python) (156)
        • 백준 (python) (65) N
      • 자료구조 | 알고리즘 (14)
      • 개발 | 프로젝트 (35)
        • Python (4)
        • Java | Spring (7)
        • Unity (3)
        • API (3)
      • CS (15)
        • Network (5)
        • SQL (2)
        • OS (4)
      • 데이터 분석 (14)
      • 기타 (12)
  • 블로그 메뉴

    • 홈
    • 태그
    • 글쓰기
    • 설정
  • 링크

    • GitHub
  • 인기 글

  • 태그

    asterisk
    백엔드
    바다코끼리
    웹크롤링
    kakao map api
    solving environment
    코딩테스트
    데이터분석
    티스토리챌린지
    Python
    프로그래머스
    파이썬
    박스플롯
    2 x n 타일링
    confusion matrix
    백엔드 개발자
    Boxplot
    오차행렬
    Greedy
    야근 지수
    카카오맵
    카카오맵 api
    API
    대입 표현식
    모델 성능 평가
    그리디 알고리즘
    프렌즈4블록
    백엔드 개발자 역량
    train_test_split
    오블완
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.0
seulll
[ 스택 / 큐 ] Programmers / 기능개발 / python
상단으로

티스토리툴바