[LeetCode][Python3] 121. Best Time to Buy and Sell Stock
2018. 9. 27. 01:04 |
프로그래밍/LeetCode
Problem :
https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/
My Solution :
class Solution:
def maxProfit(self, prices):
"""
:type prices: List[int]
:rtype: int
"""
profit = 0
low = float('inf')
for p in prices:
profit = max(profit, p - low)
low = min(low, p)
return profit
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 160. Intersection of Two Linked Lists (0) | 2018.09.28 |
---|---|
[LeetCode][Python3] 155. Min Stack (0) | 2018.09.28 |
[LeetCode][Python3] 141. Linked List Cycle (0) | 2018.09.28 |
[LeetCode][Python3] 136. Single Number (0) | 2018.09.27 |
[LeetCode][Python3] 104. Maximum Depth of Binary Tree (0) | 2018.09.27 |
[LeetCode][Python3] 101. Symmetric Tree (0) | 2018.09.27 |
[LeetCode][Python3] 100. Same Tree (0) | 2018.09.26 |
[LeetCode][Python3] 70. Climbing Stairs (0) | 2018.09.26 |
최근에 달린 댓글 최근에 달린 댓글