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
- boj 1074
- count triplets
- boj 6443
- LCS
- DirectX
- string construction
- DirectX12
- PCCE
- boj 1717
- pccp 기출문제 풀이
- dp
- pcce 기출문제 풀이
- two characters
- 프로그래밍공부
- the maximum subarray
- 2025 프로그래머스 코딩챌린지 1차예선
- the longest increasing subsequence
- boj 11657
- gas
- find the running median
- 브루트포스
- 지게차와 크레인
- lock free stack
- lock based queue
- c++
- find the town judge
- lock based stack
- making anagrams
- special string again
- ice cream parlor
Archives
- Today
- Total
오구의코딩모험
[Python] 주식가격 본문
반응형
[코딩테스트 고득점 KIT - 스택/큐]
이중 for문을 이용하여
기준으로 둔 i번째 가격이 그 다음에 나올 j초 후 가격과 비교하며
cnt 값을 증가시켰다.
마지막 값과 비교를 마치거나, 기준 가격보다 떨어진 경우
answer 값을 반환해준다.
마지막 가격은 비교할 대상이 없으므로 제외 시켰다가,
마지막에 0 값을 대입해주었다.
끝
def solution(prices):
answer = []
for i in range(len(prices)):
cnt = 1
for j in range(i+1,len(prices)):
if prices[i] <= prices[j]:
if j == len(prices)-1:
answer.append(cnt)
break
cnt += 1
elif prices[i] > prices[j]:
answer.append(cnt)
break
answer.append(0)
return answer
반응형
'프로그래밍 공부 > 프로그래머스' 카테고리의 다른 글
[Python] 디스크 컨트롤러 (0) | 2022.12.31 |
---|---|
[Python] 더 맵게 (0) | 2022.12.30 |
[Python] 주차 요금 계산 (0) | 2022.12.29 |
머쓱이 스탬프 획득! (0) | 2022.12.27 |
[Python] 기능개발 (1) | 2022.12.26 |
Comments