Python 알고리즘 인터뷰 - 문제 78. 주식을 사고팔기 가장 좋은 시점 II
2024. 3. 6. 00:02ㆍ코딩 테스트/파이썬 알고리즘 인터뷰
https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/
Best Time to Buy and Sell Stock II - LeetCode
Can you solve this real interview question? Best Time to Buy and Sell Stock II - You are given an integer array prices where prices[i] is the price of a given stock on the ith day. On each day, you may decide to buy and/or sell the stock. You can only hold
leetcode.com
전체 코드
class Solution(object):
def maxProfit(self, prices: list):
result = sum([max(prices[i + 1] - prices[i], 0) for i in range(len(prices) - 1)])
return result
'코딩 테스트 > 파이썬 알고리즘 인터뷰' 카테고리의 다른 글
파이썬 알고리즘 인터뷰 66. 회전 정렬된 배열 검색 (0) | 2024.03.06 |
---|---|
Python 알고리즘 인터뷰 - 문제 79. 키에 따른 대기열 재구성 (0) | 2024.03.06 |
240304 TIL (0) | 2024.03.04 |
Python 알고리즘 인터뷰 - 문제 47. 이진 트리의 직렬화 & 역직렬화 (1) | 2024.03.04 |
Python 알고리즘 인터뷰 - 문제 46. 두 이진 트리 병합 (0) | 2024.02.27 |