[LeetCode] Best Time to Buy and Sell
1. ๋ฌธ์ : Link
๊ฐ์ฅ ์ผ ๊ฐ์ ์ฌ์ ๊ฐ์ฅ ๋น์ผ ๊ฐ์ ํ๋ ๋ฒ์ ๊ตฌํ๋ ๋ฌธ์
2. ํ์ด
๋ฆฌ์คํธ ์ํํ๋ฉฐ min๊ฐ๊ณผ max๊ฐ์ ์ฐจ์ด return
3. ์ฝ๋
class Solution:
def maxProfit(self, prices: List[int]) -> int:
num = 10001
maxx = 0
result = 0
for p in prices:
if num > p:
num = p
else:
result = p - num
if maxx < result:
maxx = result
return maxx
'๐ป Coding Problems Solving > Array | String | Loop' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[LeetCode] Product of Array Expect Self (0) | 2022.07.09 |
---|---|
[LeetCode] Contains Duplicate (0) | 2022.07.09 |
[LeetCode] Two Sum (0) | 2022.06.30 |
[BOJ 1789] ์๋ค์ ํฉ (0) | 2022.06.26 |
[BOJ 1978] ์์์ฐพ๊ธฐ (0) | 2022.06.22 |
์ต๊ทผ๋๊ธ