기억은 짧고 기록은 길다
[프로그래머스/Programmers] 주식가격 - Python 본문
Link
코딩테스트 연습 - 주식가격
초 단위로 기록된 주식가격이 담긴 배열 prices가 매개변수로 주어질 때, 가격이 떨어지지 않은 기간은 몇 초인지를 return 하도록 solution 함수를 완성하세요. 제한사항 prices의 각 가격은 1 이상 10,00
programmers.co.kr
Solution
def solution(prices):
answer = [0] * len(prices)
for i in range(len(prices) - 1):
for j in range(i + 1, len(prices)):
answer[i] += 1
if prices[i] > prices[j]:
break
return answer
🔑 key point: if prices[i] > prices[j]: break
'CodingTest > programmers' 카테고리의 다른 글
[프로그래머스/Programmers] 최댓값과 최솟값 - Python (0) | 2021.09.22 |
---|---|
[프로그래머스/Programmers] 짝지어 제거하기 - Python (0) | 2021.09.21 |
[프로그래머스/Programmers] 이진 변환 반복하기 - Python (0) | 2021.09.21 |
[프로그래머스/Programmers] 전화번호 목록 - Python (0) | 2021.09.21 |
[프로그래머스/Programmers] 위장 - Python (0) | 2021.09.19 |
Comments