티스토리 뷰
공부 (@Deprecated)
[leetcode] 309. Best Time to Buy and Sell Stock with Cooldown
승가비 2023. 2. 3. 02:01728x90
https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/description/
Best Time to Buy and Sell Stock with Cooldown - LeetCode
Best Time to Buy and Sell Stock with Cooldown - You are given an array prices where prices[i] is the price of a given stock on the ith day. Find the maximum profit you can achieve. You may complete as many transactions as you like (i.e., buy one and sell o
leetcode.com
https://www.youtube.com/watch?v=IGIe46xw3YY
class Solution:
def maxProfit(self, prices: List[int]) -> int:
def f(i, buy, prices, size, dp):
if i >= size:
return 0
if dp[i][buy] != -1:
return dp[i][buy]
if buy == True:
dp[i][buy] = max(
-prices[i] + f(i+1, False, prices, size, dp),
0 + f(i+1, True, prices, size, dp)
)
return dp[i][buy]
dp[i][buy] = max(
prices[i] + f(i+2, True, prices, size, dp),
0 + f(i+1, False, prices, size, dp)
)
return dp[i][buy]
size = len(prices)
dp = []
for i in range(size):
dp.append({
True: -1,
False: -1
})
return f(0, True, prices, size, dp)728x90
'공부 (@Deprecated)' 카테고리의 다른 글
| [git] semantic commit messages & semantic branch names (0) | 2023.02.04 |
|---|---|
| [Python] mixin (0) | 2023.02.04 |
| [airflow] providers packages reference (0) | 2023.02.02 |
| [Jira] issue 이동 (other project) (0) | 2023.02.02 |
| [postgres] AUTO INCREMENT (0) | 2023.02.02 |
댓글
250x250
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- 테슬라 크레딧 사용
- 테슬라 추천
- wlw
- 팔로워 수 세기
- 클루지
- 김달
- 테슬라 레퍼럴
- follower
- 테슬라 리퍼럴 코드
- 인스타그램
- Bot
- 테슬라 리퍼럴 코드 생성
- Kluge
- 연애학개론
- COUNT
- 유투브
- 레퍼럴
- 책그림
- 테슬라 레퍼럴 적용 확인
- 테슬라 레퍼럴 코드 확인
- 테슬라 리퍼럴 코드 혜택
- 개리마커스
- 모델 Y 레퍼럴
- 어떻게 능력을 보여줄 것인가?
- 메디파크 내과 전문의 의학박사 김영수
- 할인
- 테슬라
- 모델y
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
글 보관함